Skip to main content

use_geography/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4pub use use_address::*;
5pub use use_boundary as boundary;
6pub use use_elevation as elevation;
7pub use use_geo_coordinate as geo_coordinate;
8pub use use_geographic_region as geographic_region;
9pub use use_map_scale as map_scale;
10pub use use_place as place;
11pub use use_projection as projection;
12pub use use_spatial_reference as spatial_reference;
13
14#[cfg(test)]
15mod tests {
16    use super::{
17        Address, AddressCountryCode, AddressLine, boundary, elevation, geo_coordinate,
18        geographic_region, map_scale, place, projection, spatial_reference,
19    };
20
21    #[test]
22    fn facade_reexports_geography_primitives() -> Result<(), Box<dyn std::error::Error>> {
23        let latitude = geo_coordinate::Latitude::new(48.8566)?;
24        let longitude = geo_coordinate::Longitude::new(2.3522)?;
25        let pair = geo_coordinate::CoordinatePair::new(latitude, longitude);
26        let coordinate = geo_coordinate::GeoCoordinate::from(pair);
27        let place_name = place::PlaceName::new("Paris")?;
28        let region_name = geographic_region::GeographicRegionName::new("Ile-de-France")?;
29        let epsg = spatial_reference::EpsgCode::new(4326)?;
30        let height = elevation::Elevation::new(35.0)?;
31        let scale = map_scale::MapScale::new(map_scale::ScaleRatio::new(10_000)?);
32
33        assert_eq!(coordinate.latitude(), latitude);
34        assert_eq!(coordinate.longitude(), longitude);
35        assert_eq!(place_name.as_str(), "Paris");
36        assert_eq!(region_name.as_str(), "Ile-de-France");
37        assert_eq!(
38            boundary::BoundaryKind::Administrative.to_string(),
39            "administrative"
40        );
41        assert_eq!(projection::ProjectionKind::Mercator.to_string(), "mercator");
42        assert_eq!(epsg.to_string(), "EPSG:4326");
43        assert!((height.meters() - 35.0).abs() < f64::EPSILON);
44        assert_eq!(scale.to_string(), "1:10000");
45        Ok(())
46    }
47
48    #[test]
49    fn facade_reexports_address_primitives() -> Result<(), Box<dyn std::error::Error>> {
50        let address = Address::new().with_line(AddressLine::new("123 Main St")?);
51        let address = Address {
52            country_code: Some(AddressCountryCode::new("us")?),
53            ..address
54        };
55
56        assert!(!address.is_empty());
57        assert!(address.has_country());
58        assert_eq!(
59            address
60                .country_code
61                .as_ref()
62                .map(AddressCountryCode::as_str),
63            Some("US")
64        );
65        Ok(())
66    }
67}