pub struct SmallString<const MAX_LEN: usize, C: SmallChar = u16> { /* private fields */ }Expand description
A stack-allocated fixed-capacity string with explicit length.
This type stores characters in a fixed-size array and maintains
an explicit length field, similar to ITensors.jl’s SmallString.
§Type Parameters
MAX_LEN: Maximum number of characters (default: 16, matching ITensors.jl)C: Character type (default:u16for ITensors.jl compatibility)
§Character Type Options
u16(default): 2 bytes per character, supports BMP (Basic Multilingual Plane)- Covers ASCII, Japanese, Chinese, Korean, and most practical characters
- Does NOT support emoji or rare characters outside BMP
char: 4 bytes per character, full Unicode support
§Example
use tensor4all_core::smallstring::SmallString;
// Default: u16 characters (ITensors.jl compatible)
let s1 = SmallString::<16>::from_str("hello").unwrap();
// Explicit char type for full Unicode support
let s2 = SmallString::<16, char>::from_str("hello 😀").unwrap();Implementations§
Source§impl<const MAX_LEN: usize, C: SmallChar> SmallString<MAX_LEN, C>
impl<const MAX_LEN: usize, C: SmallChar> SmallString<MAX_LEN, C>
Sourcepub fn from_str(s: &str) -> Result<Self, SmallStringError>
pub fn from_str(s: &str) -> Result<Self, SmallStringError>
Create a SmallString from a string slice.
Returns an error if:
- The string is longer than MAX_LEN characters
- Any character cannot be represented in the character type C
This function is allocation-free (no heap allocation).
Trait Implementations§
Source§impl<const MAX_LEN: usize, C: Clone + SmallChar> Clone for SmallString<MAX_LEN, C>
impl<const MAX_LEN: usize, C: Clone + SmallChar> Clone for SmallString<MAX_LEN, C>
Source§fn clone(&self) -> SmallString<MAX_LEN, C>
fn clone(&self) -> SmallString<MAX_LEN, C>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<const MAX_LEN: usize, C: SmallChar> Ord for SmallString<MAX_LEN, C>
impl<const MAX_LEN: usize, C: SmallChar> Ord for SmallString<MAX_LEN, C>
Source§impl<const MAX_LEN: usize, C: SmallChar> PartialOrd for SmallString<MAX_LEN, C>
impl<const MAX_LEN: usize, C: SmallChar> PartialOrd for SmallString<MAX_LEN, C>
impl<const MAX_LEN: usize, C: Copy + SmallChar> Copy for SmallString<MAX_LEN, C>
impl<const MAX_LEN: usize, C: SmallChar> Eq for SmallString<MAX_LEN, C>
Auto Trait Implementations§
impl<const MAX_LEN: usize, C> Freeze for SmallString<MAX_LEN, C>where
C: Freeze,
impl<const MAX_LEN: usize, C> RefUnwindSafe for SmallString<MAX_LEN, C>where
C: RefUnwindSafe,
impl<const MAX_LEN: usize, C> Send for SmallString<MAX_LEN, C>where
C: Send,
impl<const MAX_LEN: usize, C> Sync for SmallString<MAX_LEN, C>where
C: Sync,
impl<const MAX_LEN: usize, C> Unpin for SmallString<MAX_LEN, C>where
C: Unpin,
impl<const MAX_LEN: usize, C> UnwindSafe for SmallString<MAX_LEN, C>where
C: UnwindSafe,
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
Casts
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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