diff --git a/Cargo.lock b/Cargo.lock index 3865ec94..c1a70eac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -741,6 +741,18 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "geojson" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e26f3c45b36fccc9cf2805e61d4da6bc4bbd5a3a9589b01afa3a40eff703bd79" +dependencies = [ + "log", + "serde", + "serde_json", + "thiserror 2.0.17", +] + [[package]] name = "getrandom" version = "0.2.16" @@ -1578,6 +1590,7 @@ dependencies = [ "chrono", "ctor", "either", + "geojson", "glam", "indexmap", "ipnetwork", diff --git a/specta/Cargo.toml b/specta/Cargo.toml index 32c3660f..e16f6a84 100644 --- a/specta/Cargo.toml +++ b/specta/Cargo.toml @@ -84,6 +84,8 @@ bevy_ecs = ["dep:bevy_ecs"] bevy_input = ["dep:bevy_input", "dep:bevy_ecs", "dep:glam"] # [camino](https://docs.rs/camino) crate camino = ["dep:camino"] +## [geojson](https://docs.rs/geojson) crate +geojson = ["dep:geojson", "serde_json"] [lints] workspace = true @@ -119,6 +121,7 @@ bevy_ecs = { version = "0.17.3", optional = true, default-features = false, feat bevy_input = { version = "0.17.3", optional = true, default-features = false, features = ["std", "bevy_reflect"] } jiff = { version = "0.2", optional = true, default-features = false } camino = { version = "1.2.1", optional = true, default-features = false } +geojson = { version = "0.24", optional = true, default-features = false } [dev-dependencies] serde = { version = "1.0.228", features = ["derive"] } # TODO: Can we remove this? diff --git a/specta/src/type/legacy_impls.rs b/specta/src/type/legacy_impls.rs index 76bd5c91..73aa9010 100644 --- a/specta/src/type/legacy_impls.rs +++ b/specta/src/type/legacy_impls.rs @@ -563,3 +563,58 @@ impl_as!( camino::Utf8Path as String camino::Utf8PathBuf as String ); + +#[cfg(feature = "geojson")] +const _: () = { + use geojson::{Feature, FeatureCollection, Geometry, Value}; + + #[derive(Type)] + #[specta(rename = "GeoJsonValue", untagged, remote = Value, crate = crate, collect = false)] + #[allow(dead_code)] + pub enum GeoJsonValue { + Point(geojson::PointType), + MultiPoint(Vec), + LineString(geojson::LineStringType), + MultiLineString(Vec), + Polygon(geojson::PolygonType), + MultiPolygon(Vec), + GeometryCollection(Vec), + } + + #[derive(Type)] + #[specta(rename = "GeoJsonGeometry", remote = Geometry, crate = crate, collect = false)] + #[allow(dead_code)] + pub struct GeoJsonGeometry { + pub bbox: Option, + pub value: Value, + pub foreign_members: Option, + } + + #[derive(Type)] + #[specta(rename = "GeoJsonFeature", remote = Feature, crate = crate, collect = false)] + #[allow(dead_code)] + pub struct GeoJsonFeature { + pub bbox: Option, + pub geometry: Option, + pub id: Option, + pub properties: Option, + pub foreign_members: Option, + } + + #[derive(Type)] + #[specta(rename = "GeoJsonFeatureCollection", remote = FeatureCollection, crate = crate, collect = false)] + #[allow(dead_code)] + pub struct GeoJsonFeatureCollection { + pub bbox: Option, + pub features: Vec, + pub foreign_members: Option, + } + + #[derive(Type)] + #[specta(rename = "GeoJsonFeatureId", untagged, remote = geojson::feature::Id, crate = crate, collect = false)] + #[allow(dead_code)] + pub enum GeoJsonFeatureId { + String(String), + Number(serde_json::Number), + } +};