[−][src]Struct smallstr::SmallString
A String
-like container that can store a small number of bytes inline.
SmallString
uses a SmallVec<[u8; N]>
as its internal storage.
Methods
impl<A: Array<Item = u8>> SmallString<A>
[src]
pub fn new() -> SmallString<A>
[src]
Construct an empty string.
pub fn with_capacity(n: usize) -> SmallString<A>
[src]
Construct an empty string with enough capacity pre-allocated to store
at least n
bytes.
Will create a heap allocation only if n
is larger than the inline capacity.
pub fn from_str(s: &str) -> SmallString<A>
[src]
Construct a SmallString
by copying data from a &str
.
pub fn from_string(s: String) -> SmallString<A>
[src]
Construct a SmallString
by using an existing allocation.
pub fn from_buf(buf: A) -> Result<SmallString<A>, FromUtf8Error<A>>
[src]
Constructs a new SmallString
on the stack using UTF-8 bytes.
If the provided byte array is not valid UTF-8, an error is returned.
pub unsafe fn from_buf_unchecked(buf: A) -> SmallString<A>
[src]
Constructs a new SmallString
on the stack using the provided byte array
without checking that the array contains valid UTF-8.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid UTF-8. If this constraint is violated, it may cause
memory unsafety issues, as the Rust standard library functions assume
that &str
s are valid UTF-8.
pub fn inline_size(&self) -> usize
[src]
The maximum number of bytes this string can hold inline.
pub fn len(&self) -> usize
[src]
Returns the length of this string, in bytes.
pub fn is_empty(&self) -> bool
[src]
Returns true
if this string is empty.
pub fn capacity(&self) -> usize
[src]
Returns the number of bytes this string can hold without reallocating.
pub fn spilled(&self) -> bool
[src]
Returns true
if the data has spilled into a separate heap-allocated buffer.
ⓘImportant traits for Drain<'a>pub fn drain(&mut self) -> Drain
[src]
Empties the string and returns an iterator over its former contents.
pub fn push(&mut self, ch: char)
[src]
Appends the given char
to the end of this string.
Examples
use smallstr::SmallString; let mut s: SmallString<[u8; 8]> = SmallString::from("foo"); s.push('x'); assert_eq!(s, "foox");
pub fn push_str(&mut self, s: &str)
[src]
Appends the given string slice to the end of this string.
Examples
use smallstr::SmallString; let mut s: SmallString<[u8; 8]> = SmallString::from("foo"); s.push_str("bar"); assert_eq!(s, "foobar");
pub fn pop(&mut self) -> Option<char>
[src]
Removes the last character from this string and returns it.
Returns None
if the string is empty.
pub fn grow(&mut self, new_cap: usize)
[src]
pub fn reserve(&mut self, additional: usize)
[src]
Ensures that this string's capacity is at least additional
bytes larger
than its length.
The capacity may be increased by more than additional
bytes in order to
prevent frequent reallocations.
pub fn reserve_exact(&mut self, additional: usize)
[src]
Ensures that this string's capacity is additional
bytes larger than
its length.
pub fn shrink_to_fit(&mut self)
[src]
Shrink the capacity of the string as much as possible.
When possible, this will move the data from an external heap buffer to the string's inline storage.
pub fn truncate(&mut self, len: usize)
[src]
Shorten the string, keeping the first len
bytes.
This does not reallocate. If you want to shrink the string's capacity,
use shrink_to_fit
after truncating.
Panics
If len
does not lie on a char
boundary.
pub fn as_str(&self) -> &str
[src]
Extracts a string slice containing the entire string.
pub fn as_mut_str(&mut self) -> &mut str
[src]
Extracts a string slice containing the entire string.
pub fn clear(&mut self)
[src]
Removes all contents of the string.
pub fn remove(&mut self, idx: usize) -> char
[src]
Removes a char
from this string at a byte position and returns it.
Panics
If idx
does not lie on a char
boundary.
pub fn insert(&mut self, idx: usize, ch: char)
[src]
Inserts a char
into this string at the given byte position.
Panics
If idx
does not lie on char
boundaries.
pub fn insert_str(&mut self, idx: usize, s: &str)
[src]
Inserts a &str
into this string at the given byte position.
Panics
If idx
does not lie on char
boundaries.
pub unsafe fn as_mut_vec(&mut self) -> &mut SmallVec<A>
[src]
Returns a mutable reference to the contents of the SmallString
.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid UTF-8. If this constraint is violated, it may cause
memory unsafety issues, as the Rust standard library functions assume
that &str
s are valid UTF-8.
pub fn into_string(self) -> String
[src]
Converts the SmallString
into a String
, without reallocating if the
SmallString
has already spilled onto the heap.
pub fn retain<F: FnMut(char) -> bool>(&mut self, f: F)
[src]
Retains only the characters specified by the predicate.
In other words, removes all characters c
such that f(c)
returns false
.
This method operates in place and preserves the order of retained
characters.
Examples
use smallstr::SmallString; let mut s: SmallString<[u8; 16]> = SmallString::from("f_o_ob_ar"); s.retain(|c| c != '_'); assert_eq!(s, "foobar");
Trait Implementations
impl<A: Array<Item = u8>> AsMut<str> for SmallString<A>
[src]
impl<A: Array<Item = u8>> AsRef<str> for SmallString<A>
[src]
impl<A: Array<Item = u8>> Borrow<str> for SmallString<A>
[src]
impl<A: Array<Item = u8>> BorrowMut<str> for SmallString<A>
[src]
fn borrow_mut(&mut self) -> &mut str
[src]
impl<A: Clone + Array<Item = u8>> Clone for SmallString<A>
[src]
fn clone(&self) -> SmallString<A>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A: Array<Item = u8>> Debug for SmallString<A>
[src]
impl<A: Default + Array<Item = u8>> Default for SmallString<A>
[src]
fn default() -> SmallString<A>
[src]
impl<A: Array<Item = u8>> Deref for SmallString<A>
[src]
impl<A: Array<Item = u8>> DerefMut for SmallString<A>
[src]
impl<A: Array<Item = u8>> Display for SmallString<A>
[src]
impl<A: Array<Item = u8>> Eq for SmallString<A>
[src]
impl<'a, A: Array<Item = u8>> Extend<&'a char> for SmallString<A>
[src]
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
[src]
impl<'a, A: Array<Item = u8>> Extend<&'a str> for SmallString<A>
[src]
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)
[src]
impl<'a, A: Array<Item = u8>> Extend<Cow<'a, str>> for SmallString<A>
[src]
fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I)
[src]
impl<A: Array<Item = u8>> Extend<String> for SmallString<A>
[src]
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)
[src]
impl<A: Array<Item = u8>> Extend<char> for SmallString<A>
[src]
fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)
[src]
impl<'a, A: Array<Item = u8>> From<&'a str> for SmallString<A>
[src]
fn from(s: &str) -> SmallString<A>
[src]
impl<A: Array<Item = u8>> From<Box<str>> for SmallString<A>
[src]
fn from(s: Box<str>) -> SmallString<A>
[src]
impl<A: Array<Item = u8>> From<String> for SmallString<A>
[src]
fn from(s: String) -> SmallString<A>
[src]
impl<A: Array<Item = u8>> From<char> for SmallString<A>
[src]
fn from(ch: char) -> SmallString<A>
[src]
impl<'a, A: Array<Item = u8>> FromIterator<&'a char> for SmallString<A>
[src]
fn from_iter<I: IntoIterator<Item = &'a char>>(iter: I) -> SmallString<A>
[src]
impl<'a, A: Array<Item = u8>> FromIterator<&'a str> for SmallString<A>
[src]
fn from_iter<I: IntoIterator<Item = &'a str>>(iter: I) -> SmallString<A>
[src]
impl<'a, A: Array<Item = u8>> FromIterator<Cow<'a, str>> for SmallString<A>
[src]
fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> SmallString<A>
[src]
impl<A: Array<Item = u8>> FromIterator<String> for SmallString<A>
[src]
fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> SmallString<A>
[src]
impl<A: Array<Item = u8>> FromIterator<char> for SmallString<A>
[src]
fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> SmallString<A>
[src]
impl<A: Array<Item = u8>> Hash for SmallString<A>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A: Array<Item = u8>> Index<Range<usize>> for SmallString<A>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: Range<usize>) -> &str
[src]
impl<A: Array<Item = u8>> Index<RangeFrom<usize>> for SmallString<A>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeFrom<usize>) -> &str
[src]
impl<A: Array<Item = u8>> Index<RangeFull> for SmallString<A>
[src]
impl<A: Array<Item = u8>> Index<RangeTo<usize>> for SmallString<A>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeTo<usize>) -> &str
[src]
impl<A: Array<Item = u8>> IndexMut<Range<usize>> for SmallString<A>
[src]
impl<A: Array<Item = u8>> IndexMut<RangeFrom<usize>> for SmallString<A>
[src]
impl<A: Array<Item = u8>> IndexMut<RangeFull> for SmallString<A>
[src]
impl<A: Array<Item = u8>> IndexMut<RangeTo<usize>> for SmallString<A>
[src]
impl<A: Array<Item = u8>> Ord for SmallString<A>
[src]
fn cmp(&self, rhs: &SmallString<A>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'a, A: Array<Item = u8>> PartialEq<&'a str> for SmallString<A>
[src]
impl<'a, A: Array<Item = u8>> PartialEq<Cow<'a, str>> for SmallString<A>
[src]
impl<A, B> PartialEq<SmallString<B>> for SmallString<A> where
A: Array<Item = u8>,
B: Array<Item = u8>,
[src]
A: Array<Item = u8>,
B: Array<Item = u8>,
fn eq(&self, rhs: &SmallString<B>) -> bool
[src]
fn ne(&self, rhs: &SmallString<B>) -> bool
[src]
impl<'a, A: Array<Item = u8>> PartialEq<String> for SmallString<A>
[src]
impl<'a, A: Array<Item = u8>> PartialEq<str> for SmallString<A>
[src]
impl<A: Array<Item = u8>> PartialOrd<SmallString<A>> for SmallString<A>
[src]
fn partial_cmp(&self, rhs: &SmallString<A>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A: Array<Item = u8>> Write for SmallString<A>
[src]
Auto Trait Implementations
impl<A> Send for SmallString<A>
impl<A> Sync for SmallString<A> where
A: Sync,
A: Sync,
impl<A> Unpin for SmallString<A> where
A: Unpin,
A: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,