Struct geo_uri::GeoUri

source ·
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

source

pub fn builder() -> GeoUriBuilder

Return a builder for GeoUri.

source

pub fn parse(uri: &str) -> Result<Self, Error>

Try parsing a geo URI string into a GeoUri.

For the geo URI scheme syntax, see the propsed IEEE standard RFC 5870.

§Errors

Will return an error if the parsing fails in any way.

source

pub fn latitude(&self) -> f64

Returns the latitude coordinate.

source

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.

source

pub fn longitude(&self) -> f64

Returns the longitude coordinate.

source

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.

source

pub fn altitude(&self) -> Option<f64>

Returns the altitude coordinate (if any).

source

pub fn set_altitude(&mut self, altitude: Option<f64>)

Changes the altitude coordinate.

source

pub fn uncertainty(&self) -> Option<f64>

Returns the uncertainty around the location.

source

pub fn set_uncertainty(&mut self, uncertainty: Option<f64>) -> Result<(), Error>

Changes the uncertainty around the location.

§Errors

If the uncertainty distance is not zero or positive, an error will be returned.

Trait Implementations§

source§

impl Clone for GeoUri

source§

fn clone(&self) -> GeoUri

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GeoUri

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GeoUri

source§

fn default() -> GeoUri

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for GeoUri

Available on crate feature serde only.
source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for GeoUri

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&GeoUri> for Url

Available on crate feature url only.
source§

fn from(geo_uri: &GeoUri) -> Self

Converts to this type from the input type.
source§

impl From<GeoUri> for Url

Available on crate feature url only.
source§

fn from(geo_uri: GeoUri) -> Self

Converts to this type from the input type.
source§

impl FromStr for GeoUri

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for GeoUri

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for GeoUri

Available on crate feature serde only.
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&Url> for GeoUri

Available on crate feature url only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(url: &Url) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&str> for GeoUri

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<(f64, f64)> for GeoUri

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from((latitude, longitude): (f64, f64)) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<(f64, f64, f64)> for GeoUri

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from( (latitude, longitude, altitude): (f64, f64, f64) ) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Url> for GeoUri

Available on crate feature url only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(url: Url) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for GeoUri

Auto Trait Implementations§

§

impl Freeze for GeoUri

§

impl RefUnwindSafe for GeoUri

§

impl Send for GeoUri

§

impl Sync for GeoUri

§

impl Unpin for GeoUri

§

impl UnwindSafe for GeoUri

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,