pub enum Occurrence {
Required,
Prohibited,
Optional,
}Expand description
What a requirement demands of the elements a specification applies to.
This is the normalised form: from_xs_occurs
lowers the 0.9 spelling and from_cardinality
the 1.0 spelling, so equal intent compares equal across revisions.
Variants§
Required
The facet must be present. The 1.0 required cardinality, and the 0.9
spelling minOccurs >= 1.
Prohibited
The facet must be absent. The 1.0 prohibited cardinality, and the 0.9
spelling maxOccurs = 0.
Optional
The facet may be present or absent. The 1.0 optional cardinality, and
the 0.9 spelling minOccurs = 0 with a non-zero maxOccurs.
Implementations§
Source§impl Occurrence
impl Occurrence
Sourcepub const DEFAULT: Occurrence = Occurrence::Required
pub const DEFAULT: Occurrence = Occurrence::Required
The schema default.
Load-bearing, and the reason it is named rather than left implicit: real
IDS files lean on it. A facet writing no @cardinality at all means
required, so a reader that treats “absent” as “optional” silently
drops requirements.
Sourcepub fn from_cardinality(value: &str) -> Option<Occurrence>
pub fn from_cardinality(value: &str) -> Option<Occurrence>
Lowers the IDS 1.0 @cardinality attribute.
use openbim_ids::Occurrence;
assert_eq!(Occurrence::from_cardinality("prohibited"), Some(Occurrence::Prohibited));
assert_eq!(Occurrence::from_cardinality("Required"), None);Matching is case-sensitive because the schema enumerates lower-case tokens; accepting other spellings would mean accepting documents the schema rejects.
Sourcepub fn as_cardinality(self) -> &'static str
pub fn as_cardinality(self) -> &'static str
The IDS 1.0 @cardinality spelling of this occurrence.
Sourcepub fn from_xs_occurs(min: u32, max: Option<u32>) -> Occurrence
pub fn from_xs_occurs(min: u32, max: Option<u32>) -> Occurrence
Lowers the IDS 0.9 xs:occurs spelling.
max is None for maxOccurs="unbounded". Absent attributes must be
passed as their schema defaults of 1, not as 0 — see
Occurrence::DEFAULT.
use openbim_ids::Occurrence;
// The 0.9 and 1.0 spellings of the same intent agree.
assert_eq!(
Occurrence::from_xs_occurs(0, Some(0)),
Occurrence::from_cardinality("prohibited").unwrap()
);
assert_eq!(Occurrence::from_xs_occurs(1, None), Occurrence::Required);Sourcepub fn permits_presence(self) -> bool
pub fn permits_presence(self) -> bool
Whether the facet is allowed to appear at all.