Skip to main content

Occurrence

Enum Occurrence 

Source
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

Source

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.

Source

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.

Source

pub fn as_cardinality(self) -> &'static str

The IDS 1.0 @cardinality spelling of this occurrence.

Source

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);
Source

pub fn permits_presence(self) -> bool

Whether the facet is allowed to appear at all.

Trait Implementations§

Source§

impl Clone for Occurrence

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Occurrence

Source§

impl Debug for Occurrence

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Occurrence

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Occurrence

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Occurrence

Source§

impl Hash for Occurrence

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Occurrence

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Occurrence

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.