pub enum CityObjectType {
Known(KnownCityObjectType),
Extension(String),
}Expand description
The type member of a City Object (§ 2 The different City Objects).
Known covers the 1st- and 2nd-level City Object types defined by the
CityJSON 2.0.1 spec. Any other value is a CityJSON Extension type, which
the spec requires to start with "+" (§ 8 Extensions) – Extension
carries that string verbatim so a file using an Extension (eg
"+NoiseCityFurnitureSegment") round-trips byte for byte.
This is #[serde(untagged)] over a nested known-variants enum, not a
single flat enum mixing unit variants with Extension(String) directly:
under #[serde(untagged)], a bare unit variant (de)serializes as JSON
null, not its name (this is a documented serde quirk – untagged
dispatch tries each variant’s own Deserialize standalone, and a unit
variant’s is deserialize_unit, which only accepts null). A flat
mixed enum was tried and empirically failed this exact way: every known
name fell through to Extension because none of the unit variants ever
matched a JSON string. Nesting the known names inside their own
unit-only enum sidesteps this, because that enum, derived without
#[serde(untagged)], gets the ordinary external-tagging collapse (a
unit-only enum’s tag+content is just the bare name string).
§Match on the value, not on a reference
Each known name is also available flat, as an associated const (eg
CityObjectType::BuildingPart) – see the impl block below for the
full list. They are consts, not variants: this enum has exactly the two
variants above. That distinction bites in exactly one place, and it bites
silently, so it belongs here rather than in the small print:
match *t {
CityObjectType::Building => { /* .. */ }
CityObjectType::Extension(ref s) => { let _ = s; }
_ => {}
}Note the *. Matching a const path against a &CityObjectType – ie
match t where t: &CityObjectType, or match &t – is E0308
(“mismatched types”), and rustc’s fix-it suggests renaming the arm to a
fresh binding. That compiles, and silently turns the arm into a
catch-all that matches everything, because Building in pattern position
reads as a new irrefutable binding rather than as the constant. The _
arm is still required after Extension(ref s): the match is not
exhaustive over just the known names, since Known and Extension are
the real variants.
Variants§
Known(KnownCityObjectType)
Extension(String)
Not a core CityJSON type: a CityJSON Extension type, always spelled
with a leading "+".
Implementations§
Source§impl CityObjectType
Flat, spec-spelling access to each known variant (eg
CityObjectType::BuildingPart), so call sites read exactly like the
CityJSON type name rather than CityObjectType::Known(KnownCityObjectType::BuildingPart).
These are associated consts, not enum variants – CityObjectType
itself has exactly the two variants above – but a const path is usable
wherever a variant path would be: in expressions (x == CityObjectType::Bridge)
and, because the type derives PartialEq/Eq, in match patterns too –
but only when matching on a value. See
CityObjectType
for why that matters and how it fails silently otherwise.
impl CityObjectType
Flat, spec-spelling access to each known variant (eg
CityObjectType::BuildingPart), so call sites read exactly like the
CityJSON type name rather than CityObjectType::Known(KnownCityObjectType::BuildingPart).
These are associated consts, not enum variants – CityObjectType
itself has exactly the two variants above – but a const path is usable
wherever a variant path would be: in expressions (x == CityObjectType::Bridge)
and, because the type derives PartialEq/Eq, in match patterns too –
but only when matching on a value. See
CityObjectType
for why that matters and how it fails silently otherwise.
pub const Bridge: CityObjectType
pub const BridgePart: CityObjectType
pub const BridgeInstallation: CityObjectType
pub const BridgeConstructiveElement: CityObjectType
pub const BridgeRoom: CityObjectType
pub const BridgeFurniture: CityObjectType
pub const Building: CityObjectType
pub const BuildingPart: CityObjectType
pub const BuildingInstallation: CityObjectType
pub const BuildingConstructiveElement: CityObjectType
pub const BuildingFurniture: CityObjectType
pub const BuildingStorey: CityObjectType
pub const BuildingRoom: CityObjectType
pub const BuildingUnit: CityObjectType
pub const CityFurniture: CityObjectType
pub const CityObjectGroup: CityObjectType
pub const GenericCityObject: CityObjectType
pub const LandUse: CityObjectType
pub const OtherConstruction: CityObjectType
pub const PlantCover: CityObjectType
pub const SolitaryVegetationObject: CityObjectType
pub const TINRelief: CityObjectType
pub const Road: CityObjectType
pub const Railway: CityObjectType
pub const Waterway: CityObjectType
pub const TransportSquare: CityObjectType
pub const Tunnel: CityObjectType
pub const TunnelPart: CityObjectType
pub const TunnelInstallation: CityObjectType
pub const TunnelConstructiveElement: CityObjectType
pub const TunnelHollowSpace: CityObjectType
pub const TunnelFurniture: CityObjectType
pub const WaterBody: CityObjectType
Trait Implementations§
Source§impl Clone for CityObjectType
impl Clone for CityObjectType
Source§fn clone(&self) -> CityObjectType
fn clone(&self) -> CityObjectType
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more