Struct stylecs::StaticName

source ·
pub struct StaticName { /* private fields */ }
Expand description

A statically defined Name.

Creating a static private name

use stylecs::{static_name, Name, StaticName};

static PRIVATE: StaticName = static_name!("private");
assert_eq!(PRIVATE.to_name(), Name::private("private").unwrap());

Why use StaticName?

This type enables a minor optimization. Each Identifier guarantees that only one copy of the string it points to exists. This allows for optimizations when using names as keys in a hash map. To support this, each time an Identifier is created, the global list must be first checked and a copy of the existing value returned if it already exists.

This type allows performing this initialization once upon first access of the StaticName. This type can be converted to Name using Into/From.

Implementations§

source§

impl StaticName

source

pub fn to_name(&self) -> Name

Returns this static instance as a regular Name.

Trait Implementations§

source§

impl<'a> From<&'a StaticName> for Name

source§

fn from(value: &'a StaticName) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.