Skip to main content

Const

Enum Const 

Source
pub enum Const {
    Bool(bool),
    Int(i64),
    Float(f64),
    Str(&'static str),
    List(&'static [Const]),
    Map(&'static [(&'static str, Const)]),
}
Expand description

A declared default, in the form a generated registry can hold as a const.

The same shapes as Value, with borrowed strings and slices so nothing is allocated until somebody actually asks for the default of a setting no layer supplied.

Variants§

§

Bool(bool)

§

Int(i64)

§

Float(f64)

§

Str(&'static str)

§

List(&'static [Const])

§

Map(&'static [(&'static str, Const)])

Key-value pairs, ordered by the generator so the Value it becomes is too.

Implementations§

Source§

impl Const

Source

pub fn matches(self, value: &Value) -> bool

Whether value is this constant, or is written the same way.

The same shape compares directly, without building the Value this stands for: the strict case is the common one, it runs once per declared choice for every value supplied, and a setting with choices is usually a string — where the comparison would otherwise allocate a copy of the choice to throw away.

The shapes differing is not a mismatch, though, and this is the part worth explaining. A spec writes choice 4 under type="string" as readily as choice "4", and by the time a value reaches here it has been coerced to the declared type — so the choice is an integer and the value is the string 4, and a strict comparison refuses a value the spec plainly allows. Comparing what they are written as is the same question the coercion already answered: Ty::String turns 4 into "4", and Ty::Float turns 1 into 1.0, whose text is 1 either way. Only scalars get here — PropMeta::refuses walks a list or a table item by item first — so there is no way for a,b the string to be mistaken for [a, b] the list.

Source

pub fn to_value(self) -> Value

The owned value this stands for.

Trait Implementations§

Source§

impl Clone for Const

Source§

fn clone(&self) -> Const

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 Const

Source§

impl Debug for Const

Source§

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

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

impl PartialEq for Const

Source§

fn eq(&self, other: &Const) -> 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 Const

Auto Trait Implementations§

§

impl Freeze for Const

§

impl RefUnwindSafe for Const

§

impl Send for Const

§

impl Sync for Const

§

impl Unpin for Const

§

impl UnsafeUnpin for Const

§

impl UnwindSafe for Const

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.