Struct spinoso_symbol::Symbol
source · pub struct Symbol(/* private fields */);
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§
source§impl 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
Available on crate feature artichoke
only.
pub fn is_empty<T, U>(self, interner: &T) -> bool
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
Available on crate feature artichoke
only.
pub fn len<T, U>(self, interner: &T) -> usize
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] ⓘ
Available on crate feature artichoke
only.
pub fn bytes<T, U>(self, interner: &T) -> &[u8] ⓘ
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<'_> ⓘ
Available on crate feature artichoke
only.
pub fn inspect<T, U>(self, interner: &T) -> Inspect<'_> ⓘ
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§
source§impl From<&NonZero<u16>> for Symbol
impl From<&NonZero<u16>> for Symbol
source§fn from(sym: &NonZeroU16) -> Self
fn from(sym: &NonZeroU16) -> Self
source§impl From<&NonZero<u32>> for Symbol
impl From<&NonZero<u32>> for Symbol
source§fn from(sym: &NonZeroU32) -> Self
fn from(sym: &NonZeroU32) -> Self
source§impl From<NonZero<u16>> for Symbol
impl From<NonZero<u16>> for Symbol
source§fn from(sym: NonZeroU16) -> Self
fn from(sym: NonZeroU16) -> Self
source§impl From<NonZero<u32>> for Symbol
impl From<NonZero<u32>> for Symbol
source§fn from(sym: NonZeroU32) -> Self
fn from(sym: NonZeroU32) -> Self
source§impl Ord for Symbol
impl Ord for Symbol
source§impl PartialOrd for Symbol
impl PartialOrd for Symbol
source§impl TryFrom<&NonZero<u64>> for Symbol
impl TryFrom<&NonZero<u64>> for Symbol
source§type Error = SymbolOverflowError
type Error = SymbolOverflowError
source§impl TryFrom<&NonZero<usize>> for Symbol
impl TryFrom<&NonZero<usize>> for Symbol
source§type Error = SymbolOverflowError
type Error = SymbolOverflowError
source§impl TryFrom<NonZero<u64>> for Symbol
impl TryFrom<NonZero<u64>> for Symbol
source§type Error = SymbolOverflowError
type Error = SymbolOverflowError
source§impl TryFrom<NonZero<usize>> for Symbol
impl TryFrom<NonZero<usize>> for Symbol
source§type Error = SymbolOverflowError
type Error = SymbolOverflowError
impl Copy for Symbol
impl Eq for Symbol
impl StructuralPartialEq for Symbol
Auto Trait Implementations§
impl Freeze for Symbol
impl RefUnwindSafe for Symbol
impl Send for Symbol
impl Sync for Symbol
impl Unpin for Symbol
impl UnwindSafe for Symbol
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)