geo-uri-rs
A Rust crate for uniform resource identifiers for geographic locations (geo URIs) according to IEEE RFC 5870. This crate supports parsing and generating geo URIs in the correct format. Its 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 currently only supported coordinate reference system is WGS-84.
Usage
Just run the following to add this library to your project:
Parsing
Use either the TryFrom trait or the
parse method on strings to parse a geo URI string into a
GeoUri struct:
use GeoUri;
let geo_uri = try_from.expect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let geo_uri: GeoUri = "geo:52.107,5.134;u=2000.0".parse.expect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
It is also possible to call the parse function directly:
use GeoUri;
let geo_uri = parse.expect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Generating
Use the GeoUriBuilder to construct a GeoUri
struct. Then, use either the ToString or
Display trait to generate a geo URI string:
use GeoUri;
let geo_uri = builder
.latitude
.longitude
.uncertainty
.build
.unwrap;
assert_eq!;
assert_eq!;
It is also possible to construct a GeoUri struct from coordinate
tuples using the TryFrom trait:
use GeoUri;
let geo_uri = try_from.expect;
let geo_uri = try_from.expect;
Feature: url
You can enable the url feature to convert from and to
Url structs from the
url crate.
Enable the feature in your Cargo.toml first:
= { = "X.Y.Z", = ["url"] }
Then you can do:
use GeoUri;
use Url;
let url = parse.expect;
let geo_uri = try_from.expect;
let geo_url = from;
assert_eq!;
Note that it is always possible to transform a GeoUri into an
Url, but not always the other
way around! This is because the format of the coordinates and parameters after
the URI scheme "geo:" may be invalid!
Feature: serde
If you enable the serde feature, GeoUri will implement
serde::Serialize and
serde::Deserialize.
See the serde documentation for more information.
= { = "X.Y.Z", = ["serde"] }
License
geo-uri-rs is licensed under the MIT license (see the LICENSE file or
http://opensource.org/licenses/MIT).