Struct spinoso_symbol::Symbol
source · [−]pub struct Symbol(_);
Expand description
Identifier bound to an interned byte string.
A Symbol
allows retrieving a reference to the original interned
byte string. Equivalent Symbol
s will resolve to an identical byte string.
Symbol
s are based on a u32
index. They are cheap to compare and cheap to
copy.
Symbol
s are not constrained to the interner which created them.
Implementations
sourceimpl Symbol
impl Symbol
sourcepub const fn new(id: u32) -> Self
pub const fn new(id: u32) -> Self
Construct a new Symbol
from the given u32
.
Symbol
s constructed manually may fail to resolve to an underlying
byte string.
Symbol
s are not constrained to the interner which created them.
No runtime checks ensure that the underlying interner is called with a
Symbol
that the interner itself issued.
Examples
let sym = Symbol::new(263);
assert_eq!(sym.id(), 263);
sourcepub const fn id(self) -> u32
pub const fn id(self) -> u32
Return the u32
identifier from this Symbol
.
Examples
let sym = Symbol::new(263);
assert_eq!(sym.id(), 263);
assert_eq!(u32::from(sym), 263);
sourcepub fn is_empty<T, U>(self, interner: &T) -> bool where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
Available on crate feature artichoke
only.
pub fn is_empty<T, U>(self, interner: &T) -> bool where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
artichoke
only.Returns whether the symbol is the empty byte slice b""
in the
underlying interner.
If there symbol does not exist in the underlying interner or there is an
error looking up the symbol in the underlying interner, true
is
returned.
sourcepub fn len<T, U>(self, interner: &T) -> usize where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
Available on crate feature artichoke
only.
pub fn len<T, U>(self, interner: &T) -> usize where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
artichoke
only.Returns the length of the byte slice associated with the symbol in the underlying interner.
If there symbol does not exist in the underlying interner or there is an
error looking up the symbol in the underlying interner, 0
is returned.
sourcepub fn bytes<T, U>(self, interner: &T) -> &[u8]ⓘNotable traits for &mut [u8]impl<'_> Write for &mut [u8]impl<'_> Read for &[u8]
where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
Available on crate feature artichoke
only.
pub fn bytes<T, U>(self, interner: &T) -> &[u8]ⓘNotable traits for &mut [u8]impl<'_> Write for &mut [u8]impl<'_> Read for &[u8]
where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
artichoke
only.Returns the interned byte slice associated with the symbol in the underlying interner.
If there symbol does not exist in the underlying interner or there is an
error looking up the symbol in the underlying interner, &[]
is
returned.
sourcepub fn inspect<T, U>(self, interner: &T) -> Inspect<'_>ⓘNotable traits for Inspect<'a>impl<'a> Iterator for Inspect<'a> type Item = char;
where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
Available on crate feature artichoke
only.
pub fn inspect<T, U>(self, interner: &T) -> Inspect<'_>ⓘNotable traits for Inspect<'a>impl<'a> Iterator for Inspect<'a> type Item = char;
where
T: Intern<Symbol = U>,
U: Copy + From<Symbol>,
artichoke
only.Returns an iterator that yields a debug representation of the interned byte slice associated with the symbol in the underlying interner.
This iterator produces char
sequences like :spinoso
and
:"invalid-\xFF-utf8"
.
This function can be used to implement the Ruby method
Symbol#inspect
.
If the symbol does not exist in the underlying interner or there is an error looking up the symbol in the underlying interner, a default iterator is returned.
Trait Implementations
sourceimpl From<&NonZeroU16> for Symbol
impl From<&NonZeroU16> for Symbol
sourcefn from(sym: &NonZeroU16) -> Self
fn from(sym: &NonZeroU16) -> Self
Converts to this type from the input type.
sourceimpl From<&NonZeroU32> for Symbol
impl From<&NonZeroU32> for Symbol
sourcefn from(sym: &NonZeroU32) -> Self
fn from(sym: &NonZeroU32) -> Self
Converts to this type from the input type.
sourceimpl From<NonZeroU16> for Symbol
impl From<NonZeroU16> for Symbol
sourcefn from(sym: NonZeroU16) -> Self
fn from(sym: NonZeroU16) -> Self
Converts to this type from the input type.
sourceimpl From<NonZeroU32> for Symbol
impl From<NonZeroU32> for Symbol
sourcefn from(sym: NonZeroU32) -> Self
fn from(sym: NonZeroU32) -> Self
Converts to this type from the input type.
sourceimpl Ord for Symbol
impl Ord for Symbol
sourceimpl PartialOrd<Symbol> for Symbol
impl PartialOrd<Symbol> for Symbol
sourcefn partial_cmp(&self, other: &Symbol) -> Option<Ordering>
fn partial_cmp(&self, other: &Symbol) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl TryFrom<&NonZeroU64> for Symbol
impl TryFrom<&NonZeroU64> for Symbol
type Error = SymbolOverflowError
type Error = SymbolOverflowError
The type returned in the event of a conversion error.
sourcefn try_from(value: &NonZeroU64) -> Result<Self, Self::Error>
fn try_from(value: &NonZeroU64) -> Result<Self, Self::Error>
Performs the conversion.
sourceimpl TryFrom<&NonZeroUsize> for Symbol
impl TryFrom<&NonZeroUsize> for Symbol
type Error = SymbolOverflowError
type Error = SymbolOverflowError
The type returned in the event of a conversion error.
sourcefn try_from(value: &NonZeroUsize) -> Result<Self, Self::Error>
fn try_from(value: &NonZeroUsize) -> Result<Self, Self::Error>
Performs the conversion.
sourceimpl TryFrom<NonZeroU64> for Symbol
impl TryFrom<NonZeroU64> for Symbol
type Error = SymbolOverflowError
type Error = SymbolOverflowError
The type returned in the event of a conversion error.
sourcefn try_from(value: NonZeroU64) -> Result<Self, Self::Error>
fn try_from(value: NonZeroU64) -> Result<Self, Self::Error>
Performs the conversion.
sourceimpl TryFrom<NonZeroUsize> for Symbol
impl TryFrom<NonZeroUsize> for Symbol
type Error = SymbolOverflowError
type Error = SymbolOverflowError
The type returned in the event of a conversion error.
sourcefn try_from(value: NonZeroUsize) -> Result<Self, Self::Error>
fn try_from(value: NonZeroUsize) -> Result<Self, Self::Error>
Performs the conversion.
impl Copy for Symbol
impl Eq for Symbol
impl StructuralEq for Symbol
impl StructuralPartialEq for Symbol
Auto Trait Implementations
impl RefUnwindSafe for Symbol
impl Send for Symbol
impl Sync for Symbol
impl Unpin for Symbol
impl UnwindSafe for Symbol
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more