#[cfg(not(feature = "with-serde"))]
include!("lib.rustc_serialize.rs.in");
#[cfg(feature = "with-serde")]
include!("lib.serde.rs.in");
pub type Bbox = Vec<f64>;
pub type Position = Vec<f64>;
pub type PointType = Position;
pub type LineStringType = Vec<Position>;
pub type PolygonType = Vec<Vec<Position>>;
#[macro_use]
mod macros;
mod util;
mod crs;
pub use crs::Crs;
mod geojson;
pub use geojson::GeoJson;
mod geometry;
pub use geometry::{Geometry, Value};
mod feature;
pub use feature::Feature;
mod feature_collection;
pub use feature_collection::FeatureCollection;
#[derive(Debug)]
pub enum Error {
BboxExpectedArray,
BboxExpectedNumericValues,
CrsExpectedObject,
CrsUnknownType(String),
GeoJsonExpectedObject,
GeoJsonUnknownType,
GeometryUnknownType,
MalformedJson,
PropertiesExpectedObjectOrNull,
FeatureInvalidGeometryValue,
ExpectedStringValue,
ExpectedProperty,
ExpectedF64Value,
ExpectedArrayValue,
ExpectedObjectValue,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Error::BboxExpectedArray =>
write!(f, "Encountered non-array type for a 'bbox' object."),
Error::BboxExpectedNumericValues =>
write!(f, "Encountered non-numeric value within 'bbox' array."),
Error::CrsExpectedObject =>
write!(f, "Encountered non-object type for a 'crs' object."),
Error::CrsUnknownType(ref t) =>
write!(f, "Encountered unknown type '{}' for a 'crs' object.", t),
Error::GeoJsonExpectedObject =>
write!(f, "Encountered non-object type for GeoJSON."),
Error::GeoJsonUnknownType =>
write!(f, "Encountered unknown GeoJSON object type."),
Error::GeometryUnknownType =>
write!(f, "Encountered unknown 'geometry' object type."),
Error::MalformedJson =>
write!(f, "Encountered malformed JSON."),
Error::PropertiesExpectedObjectOrNull =>
write!(f, "Encountered neither object type nor null type for \
'properties' object."),
Error::FeatureInvalidGeometryValue =>
write!(f, "Encountered neither object type nor null type for \
'geometry' field on 'feature' object."),
Error::ExpectedStringValue =>
write!(f, "Expected a string value."),
Error::ExpectedProperty =>
write!(f, "Expected a GeoJSON 'property'."),
Error::ExpectedF64Value =>
write!(f, "Expected a floating-point value."),
Error::ExpectedArrayValue =>
write!(f, "Expected an array."),
Error::ExpectedObjectValue =>
write!(f, "Expected an object."),
}
}
}
impl std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::BboxExpectedArray => "non-array 'bbox' type",
Error::BboxExpectedNumericValues => "non-numeric 'bbox' array",
Error::CrsExpectedObject => "non-object 'crs' type",
Error::CrsUnknownType(..) => "unknown 'crs' type",
Error::GeoJsonExpectedObject => "non-object GeoJSON type",
Error::GeoJsonUnknownType => "unknown GeoJSON object type",
Error::GeometryUnknownType => "unknown 'geometry' object type",
Error::MalformedJson => "malformed JSON",
Error::PropertiesExpectedObjectOrNull =>
"neither object type nor null type for properties' object.",
Error::FeatureInvalidGeometryValue =>
"neither object type nor null type for 'geometry' field on 'feature' object.",
Error::ExpectedStringValue => "expected a string value",
Error::ExpectedProperty => "expected a GeoJSON 'property'",
Error::ExpectedF64Value => "expected a floating-point value",
Error::ExpectedArrayValue => "expected an array",
Error::ExpectedObjectValue => "expected an object",
}
}
}
trait FromObject: Sized {
fn from_object(object: &json::JsonObject) -> Result<Self, Error>;
}