[][src]Struct ichen_openprotocol::GeoLocation

pub struct GeoLocation {
    pub geo_latitude: f64,
    pub geo_longitude: f64,
}

A data structure containing a single physical geo-location.

Fields

geo_latitude: f64

Latitude

geo_longitude: f64

Longitude

Methods

impl GeoLocation[src]

pub fn new(latitude: f64, longitude: f64) -> Self[src]

Create a new GeoLocation.

Examples

// Notice this is an invalid geo-location position, but still works
// To validate the data structure, call the `validate` method.
let geo = GeoLocation::new(123.456, -987.654);
assert_eq!(123.456, geo.geo_latitude);
assert_eq!(-987.654, geo.geo_longitude);

pub fn validate(&self) -> Result<'static, ()>[src]

Validate the data structure.

Errors

Returns Err(OpenProtocolError::InvalidField) if either geo_latitude or geo_longitude is not a valid floating-point number.

Returns Err(OpenProtocolError::ConstraintViolated) if geo_latitude and geo_longitude together does not represent a valid Geo-Location position.

Examples

let geo1 = GeoLocation::new(23.456, std::f64::NEG_INFINITY);
assert_eq!(
    r#"Err(InvalidField { field: "geo_longitude", value: "-inf", description: "Infinity is not a supported value" })"#,
    format!("{:?}", geo1.validate())
);

let geo2 = GeoLocation::new(123.456, 987.654);
assert_eq!(
    r#"Err(ConstraintViolated("latitude (123.456) must be between -90 and 90"))"#,
    format!("{:?}", geo2.validate())
);

Trait Implementations

impl PartialEq<GeoLocation> for GeoLocation[src]

impl Debug for GeoLocation[src]

impl Serialize for GeoLocation[src]

impl<'de> Deserialize<'de> for GeoLocation[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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