From 7ec8dbc7d318eeb51366f681e5b2b5636d86f897 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Tue, 27 Sep 2022 17:58:48 +0200 Subject: [PATCH] Add README.md and LICENSE file Also link the files from the crate and include `README.md` as the crate documentation. --- Cargo.toml | 2 ++ LICENSE | 19 ++++++++++++++ README.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 +- 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 LICENSE create mode 100644 README.md diff --git a/Cargo.toml b/Cargo.toml index eeda2c3..3c9c106 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,8 @@ name = "geo-uri" version = "0.1.0" edition = "2021" +readme = "README.md" +license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1857a62 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +The MIT License (MIT) +Copyright (c) 2022 Paul van Tilburg + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fcc445e --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ +# geo-uri-rs + +A Rust crate (`geo-uri`) for parsing uniform resource identifiers for +geographic locations (geo URIs) according to +IEEE RFC [5870](https://www.rfc-editor.org/rfc/rfc5870). +This crate allows for parsing and generating geo URIs in the correct format. +It's parser is currently somewhat more liberal than the proposed standard. + +It supports geolocations specified by latitude and longitude, but also +optionally altitude and an uncertainty radius. +The only supported coordinate reference system is +[WGS-84](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84). + +## Usage + +Just run the following to add this library to your project: + +```sh +$ cargo add geo-uri + Updating crates.io index + Adding thiserror v??? to dependencies. +``` + +### Parsing + +Use either the [`FromStr`](std::str::FromStr) or +[`TryFrom`](std::convert::TryFrom) traits to parse a geo URI string: + +```rust +use geo_uri::GeoUri; + +let geo_uri = GeoUri::try_from("geo:52.107,5.134,3.6;u=1000"); +assert!(geo_uri.is_ok()); + +let geo_uri2 = GeoUri::from_str("geo:52.107,5.134;u=2000"); +assert!(geo_uri2.is_ok()); +``` + +It is also possible to call the parse function directly: + +```rust +use geo_uri::GeoUri; + +let geo_uri3 = GeoUri::parse("geo:52.107,5.134,3.6;u=1000"); +assert!(geo_uri3.is_ok()); +``` + +### Generating + +Use either the [`ToString`](std::string::ToString) or +[`Display`](std::fmt::Display) trait to generate an geo URI after building it: + +```rust +use geo_uri::GeoUri; + +let geo_uri = GeoUri::builder() + .latitude(52.107) + .longitude(5.134) + .uncertainty(1_000) + .build(); +assert_eq!( + geo_uri.to_string(), + String::from("geo:52.107,5.134;u=1000") +); +assert_eq!( + format!("{}", geo_uri), + String::from("geo:52.107,5.134;u=1000") +); +``` + +## License + +geo-uri-rs is licensed under the MIT license (see the `LICENSE` file or +). diff --git a/src/lib.rs b/src/lib.rs index aa08940..3858614 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! TODO: Write and include `README.md`! +#![doc = include_str!("../README.md")] use std::fmt; use std::num::{ParseFloatError, ParseIntError};