Skip to main content

EnumVariant

Struct EnumVariant 

Source
pub struct EnumVariant {
    pub ident: Ident,
    pub rename: Option<String>,
    pub names: BTreeMap<Namespace, String>,
    pub upstream: Option<Ident>,
    pub escape: Option<Escape>,
    pub carrier: Option<Type>,
}
Expand description

One variant, with whatever the declaration renamed it to.

Fields§

§ident: Ident

The variant as Rust spells it, r# and all.

§rename: Option<String>

The GLOBAL rename, which moves the canonical word every namespace defaults from.

A MIRROR has none — see upstream, which is what its rename names instead.

§names: BTreeMap<Namespace, String>

The per-namespace renames, each overriding the canonical word in that one face.

Always empty on a MIRROR: an upstream vocabulary spells itself, in one word, in every face.

§upstream: Option<Ident>

On a MIRROR, the upstream variant this one restates, when it is not spelled alike.

§escape: Option<Escape>

The POSTURE of the #[ingraph(other)] escape — the one variant carrying a WORD rather than naming a member — and None on every other variant.

Its presence is the declaration saying the vocabulary is OPEN, in either mode. A vocabulary this crate DECLARES takes Escape::Total and nothing else: the two gated postures point at a totality living in somebody else’s crate, and an open vocabulary with no upstream has no such place for one to live.

§carrier: Option<Type>

The TEXT CARRIER an escape holds its word in — the marked variant’s one unnamed field, as the declaration wrote it — and None on every other variant.

The carrier is the declaration’s choice and this crate names no type for it: the door builds one through From<&str> and reads one through AsRef<str>, so any text type satisfying that pair holds a word. What is recorded here is the TOKEN, because one row needs the type written rather than merely reachable through a bound — the key delegation, whose Inner IS this type. Every other reader of an escape goes through the two traits and needs no name at all.

None beside a Some escape is a model that marked an escape and recorded no carrier; the key row is what it costs, and the derive never builds one — see key_delegation.

Implementations§

Source§

impl EnumVariant

Source

pub fn canonical(&self) -> String

The CANONICAL word: the global rename, else the variant’s own name unraw’d.

The r# is Rust’s escape for a word that collides with its grammar and no part of the name, so a variant called r#type is canonically type — which is what a schema and a hand-written row would spell.

Source

pub fn name(&self, namespace: Namespace) -> String

The word one namespace spells this variant as: its own rename, else that namespace’s default over the canonical word.

Source

pub fn folded(&self) -> String

The word an OPEN vocabulary spells this variant with: its rename, else the Rust name in the framework’s own lower-case household — LeftShoulder is left_shoulder.

§Why an open vocabulary defaults DIFFERENTLY from a closed one

A closed vocabulary’s word is its variant’s name verbatim, because the set IS the declaration and a client reading an SDL enum sees exactly the members it publishes. An open one publishes a SCALAR, so its words meet the outside world as text — from a producer’s protobuf, a label file, a Swift enum — and the house register’s answer for text is lower case. Defaulting to the Rust spelling would put a Pascal word in a position every other producer writes in snake.

The default is what the five vocabularies this mode was measured against already spell by hand: all forty-three of their words are to_snake_case of the variant name, exactly. rename is the escape from the arithmetic, not a knob a declaration is expected to reach for.

Source

pub fn predicate(&self) -> Ident

The predicate this variant gets — is_low, is_h264.

Over the RUST spelling rather than the canonical word, because the method is Rust and its reader is looking at the variant: a #[ingraph(rename = "lo")] moves what a database stores and not what the enum is called.

Source

pub fn upstream(&self) -> Ident

The UPSTREAM variant a mirror’s variant restates — the declared rename, else its own name.

The mirror’s two From arms are written from this, so a name that answers to nothing upstream is E0599 at the arm naming it. That is the whole enforcement, and it is the compiler’s: a derive cannot see the upstream declaration, and a table of upstream names kept here would be a second copy of somebody else’s enum.

Trait Implementations§

Source§

impl Clone for EnumVariant

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 Debug for EnumVariant

Source§

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

Formats the value using the given formatter. Read more

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, 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.