pub struct Feature<G = Geometry, P = Properties> {
pub geometry: G,
pub properties: P,
pub id: Option<Id>,
pub bbox: Option<Bbox>,
pub foreign_members: ForeignMembers,
}Expand description
A GeoJSON Feature with typed Geometry and Properties.
G defaults to the Geometry union and P to Properties, matching
@types/geojson’s Feature<G = Geometry, P = GeoJsonProperties>. Pin G to
a single geometry (e.g. Point) and/or set P to your own type.
Geometry is required but may be null (RFC 7946 §3.2); that nullability
lives in G — Feature<Option<Geometry>, P> is the nullable form.
use typed_geojson::{Feature, Point};
let f: Feature<Point, &str> = Feature::new(Point::new(vec![-96.8, 32.8]), "DFW");
assert_eq!(
serde_json::to_string(&f).unwrap(),
r#"{"type":"Feature","geometry":{"type":"Point","coordinates":[-96.8,32.8]},"properties":"DFW"}"#,
);Fields§
§geometry: G§properties: P§id: Option<Id>§bbox: Option<Bbox>§foreign_members: ForeignMembersForeign members (RFC 7946 §6.1) preserved verbatim through serde and the
geojson bridge; empty when there are none. See ForeignMembers.
Implementations§
Source§impl<G, P> Feature<G, P>
impl<G, P> Feature<G, P>
Sourcepub fn new(geometry: G, properties: P) -> Self
pub fn new(geometry: G, properties: P) -> Self
A Feature with just a geometry and properties (no id/bbox, no
foreign members).
Nullability lives in G: use Feature::<Geometry, _>::new(geom, …) for
a required geometry, or Feature::<Option<Geometry>, _>::new(None, …)
for the RFC 7946 “unlocated” (null-geometry) case.