pub struct PicoStr(/* private fields */);Expand description
An interned string representation that is cheap to copy and hash, but more expensive to access.
This type takes up 8 bytes and is copyable and null-optimized (i.e.
Option<PicoStr> also takes 8 bytes).
Supports compile-time string interning via PicoStr::constant in two
flavors:
- Strings of length at most 12 containing only chars from ‘a’-‘z’, ‘1’-‘4’, and ‘-’ are stored inline in the number
- Other strings can be compile-time interned the same way, but must first
be added to the list in
exceptions::LIST.
No such restrictions apply at runtime (via PicoStr::intern).
Implementations§
Source§impl PicoStr
impl PicoStr
Sourcepub fn get(string: &str) -> Option<PicoStr>
pub fn get(string: &str) -> Option<PicoStr>
Try to create a PicoStr, but don’t intern it if it does not exist yet.
This is useful to try to compare against one or multiple PicoStr
without interning needlessly.
Will always return Some(_) if the string can be represented inline.
Sourcepub const fn constant(string: &'static str) -> PicoStr
pub const fn constant(string: &'static str) -> PicoStr
Creates a compile-time constant PicoStr.
Should only be used in const contexts because it can panic.
Sourcepub const fn try_constant(string: &str) -> Result<PicoStr, EncodingError>
pub const fn try_constant(string: &str) -> Result<PicoStr, EncodingError>
Try to intern a string statically at compile-time.
Sourcepub fn resolve(self) -> ResolvedPicoStr
pub fn resolve(self) -> ResolvedPicoStr
Resolve to a decoded string.
Trait Implementations§
impl Copy for PicoStr
impl Eq for PicoStr
impl StructuralPartialEq for PicoStr
Auto Trait Implementations§
impl Freeze for PicoStr
impl RefUnwindSafe for PicoStr
impl Send for PicoStr
impl Sync for PicoStr
impl Unpin for PicoStr
impl UnwindSafe for PicoStr
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more