[−][src]Struct smol_str::SmolStr
A SmolStr
is a string type that has the following properties:
size_of::<SmolStr>() == size_of::<String>()
Clone
isO(1)
- Strings are stack-allocated if they are:
- Up to 22 bytes long
- Longer than 22 bytes, but substrings of
WS
(see below). Such strings consist solely of consecutive newlines, followed by consecutive spaces
- If a string does not satisfy the aforementioned conditions, it is heap-allocated
Unlike String
, however, SmolStr
is immutable. The primary use case for
SmolStr
is a good enough default storage for tokens of typical programming
languages. Strings consisting of a series of newlines, followed by a series of
whitespace are a typical pattern in computer programs because of indentation.
Note that a specialized interner might be a better solution for some use cases.
Methods
impl SmolStr
[src]
pub fn new<T>(text: T) -> SmolStr where
T: Into<String> + AsRef<str>,
[src]
T: Into<String> + AsRef<str>,
pub fn as_str(&self) -> &str
[src]
pub fn to_string(&self) -> String
[src]
pub fn len(&self) -> usize
[src]
pub fn is_empty(&self) -> bool
[src]
pub fn is_heap_allocated(&self) -> bool
[src]
Trait Implementations
impl Default for SmolStr
[src]
impl Clone for SmolStr
[src]
fn clone(&self) -> SmolStr
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Ord for SmolStr
[src]
fn cmp(&self, other: &SmolStr) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl<T> From<T> for SmolStr where
T: Into<String> + AsRef<str>,
[src]
T: Into<String> + AsRef<str>,
impl From<SmolStr> for String
[src]
impl Eq for SmolStr
[src]
impl PartialOrd<SmolStr> for SmolStr
[src]
fn partial_cmp(&self, other: &SmolStr) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialEq<SmolStr> for SmolStr
[src]
fn eq(&self, other: &SmolStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<str> for SmolStr
[src]
fn eq(&self, other: &str) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<SmolStr> for str
[src]
fn eq(&self, other: &SmolStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<&'a str> for SmolStr
[src]
fn eq(&self, other: &&'a str) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<SmolStr> for &'a str
[src]
fn eq(&self, other: &SmolStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<String> for SmolStr
[src]
fn eq(&self, other: &String) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<SmolStr> for String
[src]
fn eq(&self, other: &SmolStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<&'a String> for SmolStr
[src]
fn eq(&self, other: &&'a String) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<SmolStr> for &'a String
[src]
fn eq(&self, other: &SmolStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Deref for SmolStr
[src]
impl Debug for SmolStr
[src]
impl Display for SmolStr
[src]
impl Hash for SmolStr
[src]
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromIterator<char> for SmolStr
[src]
fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> SmolStr
[src]
impl Borrow<str> for SmolStr
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,