pub struct String32(/* private fields */);
Expand description
A string that is indexed by u32
instead of usize
.
On 64-bit platforms, String32
only requires 16 bytes to store the pointer, length, and capacity. String
by comparison requires 24 bytes, plus padding.
Implementations§
Source§impl String32
impl String32
Sourcepub fn with_capacity(cap: u32) -> Self
pub fn with_capacity(cap: u32) -> Self
Create an empty String32
with enough capacity to hold cap
bytes.
§Examples
let mut s = String32::with_capacity(1);
let cap = s.capacity();
s.push('\n');
assert_eq!(cap, s.capacity());
Sourcepub fn capacity(&self) -> u32
pub fn capacity(&self) -> u32
Return the capacity of this String32
in bytes.
§Examples
let mut s = String32::new();
assert_eq!(0, s.capacity());
s.push('\n');
assert!(s.capacity() > 0);
Sourcepub fn pop(&mut self) -> Option<char>
pub fn pop(&mut self) -> Option<char>
Pop a char
from the end of this String32
.
§Examples
let mut s = String32::try_from("\n").unwrap();
assert_eq!(s.pop(), Some('\n'));
assert_eq!(s.pop(), None);
Sourcepub fn insert_str<S>(&mut self, idx: u32, s: S)
pub fn insert_str<S>(&mut self, idx: u32, s: S)
Sourcepub fn reserve(&mut self, additional: u32)
pub fn reserve(&mut self, additional: u32)
Reserve space for additional bytes.
§Examples
let mut s = String32::try_from("abc").unwrap();
s.reserve(10);
println!("{}", s.capacity());
assert!(s.capacity() >= 13);
Sourcepub fn reserve_exact(&mut self, additional: u32)
pub fn reserve_exact(&mut self, additional: u32)
Reserve space for an exact number of bytes.
§Examples
let mut s = String32::with_capacity(5);
s.reserve_exact(10);
assert!(s.capacity() >= 10);
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink the capacity of this String32
to match its length.
§Examples
let mut s = String32::with_capacity(10);
s.shrink_to_fit();
assert_eq!(0, s.capacity());
Sourcepub fn truncate(&mut self, new_len: u32)
pub fn truncate(&mut self, new_len: u32)
Shortens this String32
to the specified length.
§Examples
let mut s = String32::try_from("abcde").unwrap();
s.truncate(3);
assert_eq!(s, "abc");
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Truncates the String32
into an empty string.
§Examples
let mut s = String32::try_from("abc").unwrap();
s.clear();
assert!(s.is_empty());
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Converts a String32
into a vector of bytes.
§Examples
let s = String32::try_from("123").unwrap();
let v = s.into_bytes();
assert_eq!(v, b"123");
Sourcepub fn into_boxed_str(self) -> Box<str>
pub fn into_boxed_str(self) -> Box<str>
Sourcepub unsafe fn from_raw_parts(buf: *mut u8, len: u32, cap: u32) -> Self
pub unsafe fn from_raw_parts(buf: *mut u8, len: u32, cap: u32) -> Self
Create a new String32
from a raw pointer and corresponding length/capacity.
§Safety
Sourcepub fn from_utf16(v: &[u16]) -> Result<Self, FromUtf16Error>
pub fn from_utf16(v: &[u16]) -> Result<Self, FromUtf16Error>
Sourcepub fn from_utf16_lossy(v: &[u16]) -> Self
pub fn from_utf16_lossy(v: &[u16]) -> Self
Methods from Deref<Target = Str32>§
Sourcepub fn as_mut_str(&mut self) -> &mut str
pub fn as_mut_str(&mut self) -> &mut str
Convert a &mut Str32
to a &mut str
slice.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Converts the Str32
to a byte slice.
§Examples
let s: &Str32 = "123".try_into().unwrap();
assert_eq!(b"123", s.as_bytes());
Sourcepub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Converts the Str32
to a byte slice.
§Examples
let mut s = String32::try_from("123").unwrap();
let bytes = unsafe { s.as_bytes_mut() };
assert_eq!(b"123", bytes);
§Safety
See str::as_bytes_mut
.
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Converts the Str32
to a mutable raw pointer.
The caller must ensure that the string slice is only modified in a way that ensures it is always valid UTF-8.
Sourcepub fn len(&self) -> u32
pub fn len(&self) -> u32
Returns the length of the Str32
in bytes.
§Examples
let s: &Str32 = "test".try_into().unwrap();
assert_eq!(4, s.len());
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the Str32
is empty.
§Examples
let s: &Str32 = "".try_into().unwrap();
assert!(s.is_empty());
Sourcepub fn char_indices(&self) -> impl DoubleEndedIterator<Item = (u32, char)> + '_
pub fn char_indices(&self) -> impl DoubleEndedIterator<Item = (u32, char)> + '_
Returns an iterator over the characters of the Str32
, and their byte indices.
Sourcepub fn lines(&self) -> impl DoubleEndedIterator<Item = &Self> + '_
pub fn lines(&self) -> impl DoubleEndedIterator<Item = &Self> + '_
Returns an iterator over the lines of a &Str32
.
Sourcepub fn split_ascii_whitespace(
&self,
) -> impl DoubleEndedIterator<Item = &Self> + '_
pub fn split_ascii_whitespace( &self, ) -> impl DoubleEndedIterator<Item = &Self> + '_
Returns an iterator over the ASCII-whitespace-delimited words of a &Str32
.
Sourcepub fn split_at(&self, mid: u32) -> (&Self, &Self)
pub fn split_at(&self, mid: u32) -> (&Self, &Self)
Splits a &Str32
in two at the given byte index.
§Panics
Panics if mid
is not a UTF-8 code point boundary.
Sourcepub fn split_at_mut(&mut self, mid: u32) -> (&mut Self, &mut Self)
pub fn split_at_mut(&mut self, mid: u32) -> (&mut Self, &mut Self)
Splits a &mut Str32
in two at the given byte index.
§Panics
Panics if mid
is not a UTF-8 code point boundary.
Sourcepub fn split_whitespace(&self) -> impl DoubleEndedIterator<Item = &Self> + '_
pub fn split_whitespace(&self) -> impl DoubleEndedIterator<Item = &Self> + '_
Returns an iterator over the whitespace-delimited words of a &Str32
.
Sourcepub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
Checks if two string slices are equal, ignoring ASCII case mismatches.
Sourcepub fn escape_debug(&self) -> EscapeDebug<'_>
pub fn escape_debug(&self) -> EscapeDebug<'_>
Return an iterator over the string slice’s chars, each escaped according to char::escape_debug
.
Sourcepub fn escape_default(&self) -> EscapeDefault<'_>
pub fn escape_default(&self) -> EscapeDefault<'_>
Return an iterator over the string slice’s chars, each escaped according to char::escape_default
.
Sourcepub fn escape_unicode(&self) -> EscapeUnicode<'_>
pub fn escape_unicode(&self) -> EscapeUnicode<'_>
Return an iterator over the string slice’s chars, each escaped according to char::escape_unicode
.
Sourcepub fn is_char_boundary(&self, index: u32) -> bool
pub fn is_char_boundary(&self, index: u32) -> bool
Returns whether the given index corresponds to a char
boundary.
Sourcepub fn make_ascii_lowercase(&mut self)
pub fn make_ascii_lowercase(&mut self)
Converts all uppercase ASCII characters to lowercase.
§Examples
let mut s = String32::try_from("ABC").unwrap();
s.make_ascii_lowercase();
assert_eq!("abc", s);
Sourcepub fn make_ascii_uppercase(&mut self)
pub fn make_ascii_uppercase(&mut self)
Converts all lowercase ASCII characters to uppercase.
§Examples
let mut s = String32::try_from("abc").unwrap();
s.make_ascii_uppercase();
assert_eq!("ABC", s);
Sourcepub fn parse<F: FromStr>(&self) -> Result<F, F::Err>
pub fn parse<F: FromStr>(&self) -> Result<F, F::Err>
Parses a &Str32
slice into another type.
§Errors
Will return Err
if this &Str32
slice cannot be parsed into the desired type.
Err
: string32::TryFromStringError
Sourcepub fn to_lowercase(&self) -> String32
pub fn to_lowercase(&self) -> String32
Sourcepub fn to_uppercase(&self) -> String32
pub fn to_uppercase(&self) -> String32
Sourcepub fn to_ascii_lowercase(&self) -> String32
pub fn to_ascii_lowercase(&self) -> String32
Sourcepub fn to_ascii_uppercase(&self) -> String32
pub fn to_ascii_uppercase(&self) -> String32
Sourcepub fn trim(&self) -> &Self
pub fn trim(&self) -> &Self
Returns a substring of this string with leading and trailing whitespace removed.
§Examples
let s: &Str32 = " test\t\n ".try_into().unwrap();
assert_eq!("test", s.trim());
Sourcepub fn trim_start(&self) -> &Self
pub fn trim_start(&self) -> &Self
Returns a substring of this string with leading whitespace removed.
§Examples
let s: &Str32 = " test\t\n ".try_into().unwrap();
assert_eq!("test\t\n ", s.trim_start());
Trait Implementations§
Source§impl AddAssign<&Str32> for String32
impl AddAssign<&Str32> for String32
Source§fn add_assign(&mut self, rhs: &Str32)
fn add_assign(&mut self, rhs: &Str32)
+=
operation. Read moreSource§impl AddAssign<&str> for String32
impl AddAssign<&str> for String32
Source§fn add_assign(&mut self, rhs: &str)
fn add_assign(&mut self, rhs: &str)
+=
operation. Read more