pub struct ReferenceSystem {
pub base_url: String,
pub segments: Vec<String>,
}Expand description
A reference system following the OGC Name Type Specification.
The format follows: http://www.opengis.net/def/crs/{authority}/{version}/{code}
where:
{authority}designates the authority responsible for the definition of this CRS (usually “EPSG” or “OGC”){version}designates the specific version of the CRS (use “0” if there is no version){code}is the identifier for the specific coordinate reference system
That three-element form is what OGC names and what every real file uses,
but it is not what makes a referenceSystem legal. The normative
constraint in metadata.schema.json is a prefix pattern and nothing else:
"referenceSystem": {
"type": "string",
"pattern": "^(http|https)://www.opengis.net/def/crs/"
}So .../crs/EPSG/0/4326/extra and .../crs/EPSG/0/7415/ are both legal
CityJSON, and an earlier version of this type rejected them outright by
demanding exactly three /-separated elements. That is the same
rejects-legal defect as the old Address, and the fix is the same:
stop inventing structure the format does not mandate.
Hence segments rather than three named fields. It holds the path
elements after .../def/crs/ verbatim, so ReferenceSystem::to_url can
rebuild any legal URL byte for byte – including a trailing slash, which
is simply a final empty element. The OGC reading is still available, as
ReferenceSystem::authority, ReferenceSystem::version and
ReferenceSystem::code, which return None when the URL does not have
that shape. Keeping the three as plain fields alongside the verbatim
path was the obvious alternative and is a trap: the two representations
can disagree, and then to_url silently contradicts the fields.
In JSON this is a single string, not an object, so the derive needs
telling how to get between the two. #[serde(try_from/into)] does exactly
that and nothing else: Serialize and Deserialize stay derived, and
the conversion is ordinary TryFrom/From code that serde calls on
either side of a plain String. This replaces a hand-written Serialize
and Deserialize pair, which violated the crate’s derived-only rule –
hand-written impls are the one place a field can be silently dropped or
reshaped without any type-level trace, which is the whole reason for the
rule.
Fields§
§base_url: StringEverything up to and including .../def/crs, with no trailing slash.
segments: Vec<String>The /-separated path elements after .../def/crs/, verbatim. OGC
names the first three {authority}/{version}/{code}; the schema
requires no particular number of them.
Implementations§
Source§impl ReferenceSystem
impl ReferenceSystem
Sourcepub fn new(
base_url: Option<String>,
authority: String,
version: String,
code: String,
) -> Self
pub fn new( base_url: Option<String>, authority: String, version: String, code: String, ) -> Self
The ordinary three-element OGC form.
The {authority} element, or None if this URL has no such element.
Sourcepub fn to_url(&self) -> String
pub fn to_url(&self) -> String
Rebuild the URL. Exact for every input ReferenceSystem::from_url
accepts, whatever its element count – segments is stored verbatim,
so there is nothing to reconstruct incorrectly.
Sourcepub fn from_url(url: &str) -> Result<Self>
pub fn from_url(url: &str) -> Result<Self>
Parse a referenceSystem string.
The only thing checked is the prefix, because the prefix is the only
thing metadata.schema.json constrains. The OGC three-element form is
a convention this honours (see ReferenceSystem::authority and
friends) but does not enforce, so a longer or shorter path is carried
through rather than rejected.
Trait Implementations§
Source§impl Clone for ReferenceSystem
impl Clone for ReferenceSystem
Source§fn clone(&self) -> ReferenceSystem
fn clone(&self) -> ReferenceSystem
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ReferenceSystem
impl Debug for ReferenceSystem
Source§impl<'de> Deserialize<'de> for ReferenceSystem
impl<'de> Deserialize<'de> for ReferenceSystem
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<ReferenceSystem> for String
The two conversions #[serde(try_from = "String", into = "String")] calls.
They carry no serde logic of their own – they are the same to_url and
from_url the rest of the crate uses.
impl From<ReferenceSystem> for String
The two conversions #[serde(try_from = "String", into = "String")] calls.
They carry no serde logic of their own – they are the same to_url and
from_url the rest of the crate uses.