pub struct GeoUri { /* private fields */ }
Expand description
A uniform resource identifier for geographic locations (geo URI).
§Examples
§Parsing
You can get a GeoUri
by converting it from a geo URI string (&str
):
use geo_uri::GeoUri;
let geo_uri = GeoUri::try_from("geo:52.107,5.134,3.6;u=1000")?;
assert_eq!(geo_uri.latitude(), 52.107);
assert_eq!(geo_uri.longitude(), 5.134);
assert_eq!(geo_uri.altitude(), Some(3.6));
assert_eq!(geo_uri.uncertainty(), Some(1000.0));
or by calling the parse
method on a string (using the TryFrom
trait):
use geo_uri::GeoUri;
let geo_uri: GeoUri = "geo:52.107,5.134;u=2000.0".parse()?;
assert_eq!(geo_uri.latitude(), 52.107);
assert_eq!(geo_uri.longitude(), 5.134);
assert_eq!(geo_uri.altitude(), None);
assert_eq!(geo_uri.uncertainty(), Some(2000.0));
It is also possible to call the parse function directly:
use geo_uri::GeoUri;
let geo_uri = GeoUri::parse("geo:52.107,5.134,3.6")?;
assert_eq!(geo_uri.latitude(), 52.107);
assert_eq!(geo_uri.longitude(), 5.134);
assert_eq!(geo_uri.altitude(), Some(3.6));
assert_eq!(geo_uri.uncertainty(), None);
§Generating
To get an geo URI string from some coordinates, use the GeoUriBuilder
:
use geo_uri::GeoUri;
let geo_uri = GeoUri::builder()
.latitude(52.107)
.longitude(5.134)
.uncertainty(1_000.0)
.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")
);
It is also possible to construct a GeoUri
struct from coordinate tuples
using the TryFrom
trait:
use geo_uri::GeoUri;
let geo_uri = GeoUri::try_from((52.107, 5.134)).expect("valid coordinates");
let geo_uri = GeoUri::try_from((52.107, 5.134, 3.6)).expect("valid coordinates");
§See also
For the proposed IEEE standard, see RFC 5870.
Implementations§
source§impl GeoUri
impl GeoUri
sourcepub fn builder() -> GeoUriBuilder
pub fn builder() -> GeoUriBuilder
Return a builder for GeoUri
.
sourcepub fn set_latitude(&mut self, latitude: f64) -> Result<(), Error>
pub fn set_latitude(&mut self, latitude: f64) -> Result<(), Error>
Changes the latitude coordinate.
§Errors
If the latitude is out of range for the coordinate reference system, an error will be returned.
sourcepub fn set_longitude(&mut self, longitude: f64) -> Result<(), Error>
pub fn set_longitude(&mut self, longitude: f64) -> Result<(), Error>
Changes the longitude coordinate.
§Errors
If the longitude is out of range for the coordinate reference system, an error will be returned.
sourcepub fn set_altitude(&mut self, altitude: Option<f64>)
pub fn set_altitude(&mut self, altitude: Option<f64>)
Changes the altitude coordinate.
sourcepub fn uncertainty(&self) -> Option<f64>
pub fn uncertainty(&self) -> Option<f64>
Returns the uncertainty around the location.
Trait Implementations§
source§impl<'de> Deserialize<'de> for GeoUri
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for GeoUri
serde
only.