pub type BoundedString = ArrayString<U63>;
Expand description
A fixed capacity copy-able string.
Aliased Typeยง
pub struct BoundedString { /* private fields */ }
Implementations
Sourceยงimpl<SIZE> ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> ArrayString<SIZE>where
SIZE: Capacity,
Sourcepub fn new() -> ArrayString<SIZE>
pub fn new() -> ArrayString<SIZE>
Creates new empty string.
let string = SmallString::new();
assert!(string.is_empty());
Sourcepub fn try_from_str<S>(s: S) -> Result<ArrayString<SIZE>, OutOfBounds>
pub fn try_from_str<S>(s: S) -> Result<ArrayString<SIZE>, OutOfBounds>
Creates new ArrayString
from string slice if length is lower or equal to capacity
, otherwise returns an error.
let string = SmallString::try_from_str("My String")?;
assert_eq!(string.as_str(), "My String");
assert_eq!(SmallString::try_from_str("")?.as_str(), "");
let out_of_bounds = "0".repeat(SmallString::capacity() as usize + 1);
assert!(SmallString::try_from_str(out_of_bounds).is_err());
Sourcepub fn from_str_truncate<S>(string: S) -> ArrayString<SIZE>
pub fn from_str_truncate<S>(string: S) -> ArrayString<SIZE>
Creates new ArrayString
from string slice truncating size if bigger than capacity
.
let string = SmallString::from_str_truncate("My String");
println!("{}", string);
let truncate = "0".repeat(SmallString::capacity() as usize + 1);
let truncated = "0".repeat(SmallString::capacity().into());
let string = SmallString::from_str_truncate(&truncate);
assert_eq!(string.as_str(), truncated);
Sourcepub unsafe fn from_str_unchecked<S>(string: S) -> ArrayString<SIZE>
pub unsafe fn from_str_unchecked<S>(string: S) -> ArrayString<SIZE>
Creates new ArrayString
from string slice assuming length is appropriate.
ยงSafety
Itโs UB if string.len()
> capacity
.
let filled = "0".repeat(SmallString::capacity().into());
let string = unsafe {
SmallString::from_str_unchecked(&filled)
};
assert_eq!(string.as_str(), filled.as_str());
// Undefined behavior, don't do it
// let out_of_bounds = "0".repeat(SmallString::capacity().into() + 1);
// let ub = unsafe { SmallString::from_str_unchecked(out_of_bounds) };
Sourcepub fn try_from_iterator<U, I>(
iter: I,
) -> Result<ArrayString<SIZE>, OutOfBounds>
pub fn try_from_iterator<U, I>( iter: I, ) -> Result<ArrayString<SIZE>, OutOfBounds>
Creates new ArrayString
from string slice iterator if total length is lower or equal to capacity
, otherwise returns an error.
let string = MaxString::try_from_iterator(&["My String", " My Other String"][..])?;
assert_eq!(string.as_str(), "My String My Other String");
let out_of_bounds = (0..100).map(|_| "000");
assert!(SmallString::try_from_iterator(out_of_bounds).is_err());
Sourcepub fn from_iterator<U, I>(iter: I) -> ArrayString<SIZE>
pub fn from_iterator<U, I>(iter: I) -> ArrayString<SIZE>
Creates new ArrayString
from string slice iterator truncating size if bigger than capacity
.
let string = MaxString::from_iterator(&["My String", " Other String"][..]);
assert_eq!(string.as_str(), "My String Other String");
let out_of_bounds = (0..400).map(|_| "000");
let truncated = "0".repeat(SmallString::capacity().into());
let truncate = SmallString::from_iterator(out_of_bounds);
assert_eq!(truncate.as_str(), truncated.as_str());
Sourcepub unsafe fn from_iterator_unchecked<U, I>(iter: I) -> ArrayString<SIZE>
pub unsafe fn from_iterator_unchecked<U, I>(iter: I) -> ArrayString<SIZE>
Creates new ArrayString
from string slice iterator assuming length is appropriate.
ยงSafety
Itโs UB if iter.map(|c| c.len()).sum()
> capacity
.
let string = unsafe {
MaxString::from_iterator_unchecked(&["My String", " My Other String"][..])
};
assert_eq!(string.as_str(), "My String My Other String");
// Undefined behavior, don't do it
// let out_of_bounds = (0..400).map(|_| "000");
// let undefined_behavior = unsafe {
// SmallString::from_iterator_unchecked(out_of_bounds)
// };
Sourcepub fn try_from_chars<I>(iter: I) -> Result<ArrayString<SIZE>, OutOfBounds>where
I: IntoIterator<Item = char>,
pub fn try_from_chars<I>(iter: I) -> Result<ArrayString<SIZE>, OutOfBounds>where
I: IntoIterator<Item = char>,
Creates new ArrayString
from char iterator if total length is lower or equal to capacity
, otherwise returns an error.
let string = SmallString::try_from_chars("My String".chars())?;
assert_eq!(string.as_str(), "My String");
let out_of_bounds = "0".repeat(SmallString::capacity() as usize + 1);
assert!(SmallString::try_from_chars(out_of_bounds.chars()).is_err());
Sourcepub fn from_chars<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = char>,
pub fn from_chars<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = char>,
Creates new ArrayString
from char iterator truncating size if bigger than capacity
.
let string = SmallString::from_chars("My String".chars());
assert_eq!(string.as_str(), "My String");
let out_of_bounds = "0".repeat(SmallString::capacity() as usize + 1);
let truncated = "0".repeat(SmallString::capacity().into());
let truncate = SmallString::from_chars(out_of_bounds.chars());
assert_eq!(truncate.as_str(), truncated.as_str());
Sourcepub unsafe fn from_chars_unchecked<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = char>,
pub unsafe fn from_chars_unchecked<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = char>,
Creates new ArrayString
from char iterator assuming length is appropriate.
ยงSafety
Itโs UB if iter.map(|c| c.len_utf8()).sum()
> capacity
.
let string = unsafe { SmallString::from_chars_unchecked("My String".chars()) };
assert_eq!(string.as_str(), "My String");
// Undefined behavior, don't do it
// let out_of_bounds = "000".repeat(400);
// let undefined_behavior = unsafe { SmallString::from_chars_unchecked(out_of_bounds.chars()) };
Sourcepub fn try_from_utf8<B>(slice: B) -> Result<ArrayString<SIZE>, Error>
pub fn try_from_utf8<B>(slice: B) -> Result<ArrayString<SIZE>, Error>
Creates new ArrayString
from byte slice, returning Utf8
on invalid utf-8 data or OutOfBounds
if bigger than capacity
let string = SmallString::try_from_utf8("My String")?;
assert_eq!(string.as_str(), "My String");
let invalid_utf8 = [0, 159, 146, 150];
assert_eq!(SmallString::try_from_utf8(invalid_utf8), Err(Error::Utf8));
let out_of_bounds = "0000".repeat(400);
assert_eq!(SmallString::try_from_utf8(out_of_bounds.as_bytes()), Err(Error::OutOfBounds));
Sourcepub fn from_utf8<B>(slice: B) -> Result<ArrayString<SIZE>, Utf8>
pub fn from_utf8<B>(slice: B) -> Result<ArrayString<SIZE>, Utf8>
Creates new ArrayString
from byte slice, returning Utf8
on invalid utf-8 data, truncating if bigger than capacity
.
let string = SmallString::from_utf8("My String")?;
assert_eq!(string.as_str(), "My String");
let invalid_utf8 = [0, 159, 146, 150];
assert_eq!(SmallString::from_utf8(invalid_utf8), Err(Utf8));
let out_of_bounds = "0".repeat(300);
assert_eq!(SmallString::from_utf8(out_of_bounds.as_bytes())?.as_str(),
"0".repeat(SmallString::capacity().into()).as_str());
Sourcepub unsafe fn from_utf8_unchecked<B>(slice: B) -> ArrayString<SIZE>
pub unsafe fn from_utf8_unchecked<B>(slice: B) -> ArrayString<SIZE>
Creates new ArrayString
from byte slice assuming itโs utf-8 and of a appropriate size.
ยงSafety
Itโs UB if slice
is not a valid utf-8 string or slice.len()
> capacity
.
let string = unsafe { SmallString::from_utf8_unchecked("My String") };
assert_eq!(string.as_str(), "My String");
// Undefined behavior, don't do it
// let out_of_bounds = "0".repeat(300);
// let ub = unsafe { SmallString::from_utf8_unchecked(out_of_bounds)) };
Sourcepub fn try_from_utf16<B>(slice: B) -> Result<ArrayString<SIZE>, Error>
pub fn try_from_utf16<B>(slice: B) -> Result<ArrayString<SIZE>, Error>
Creates new ArrayString
from u16
slice, returning Utf16
on invalid utf-16 data or OutOfBounds
if bigger than capacity
let music = [0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0x0069, 0x0063];
let string = SmallString::try_from_utf16(music)?;
assert_eq!(string.as_str(), "๐music");
let invalid_utf16 = [0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063];
assert_eq!(SmallString::try_from_utf16(invalid_utf16), Err(Error::Utf16));
let out_of_bounds: Vec<_> = (0..300).map(|_| 0).collect();
assert_eq!(SmallString::try_from_utf16(out_of_bounds), Err(Error::OutOfBounds));
Sourcepub fn from_utf16<B>(slice: B) -> Result<ArrayString<SIZE>, Utf16>
pub fn from_utf16<B>(slice: B) -> Result<ArrayString<SIZE>, Utf16>
Creates new ArrayString
from u16
slice, returning Utf16
on invalid utf-16 data, truncating if bigger than capacity
.
let music = [0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0x0069, 0x0063];
let string = SmallString::from_utf16(music)?;
assert_eq!(string.as_str(), "๐music");
let invalid_utf16 = [0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063];
assert_eq!(SmallString::from_utf16(invalid_utf16), Err(Utf16));
let out_of_bounds: Vec<u16> = (0..300).map(|_| 0).collect();
assert_eq!(SmallString::from_utf16(out_of_bounds)?.as_str(),
"\0".repeat(SmallString::capacity().into()).as_str());
Sourcepub fn from_utf16_lossy<B>(slice: B) -> ArrayString<SIZE>
pub fn from_utf16_lossy<B>(slice: B) -> ArrayString<SIZE>
Creates new ArrayString
from u16
slice, replacing invalid utf-16 data with REPLACEMENT_CHARACTER
(\u{FFFD}) and truncating size if bigger than capacity
let music = [0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0x0069, 0x0063];
let string = SmallString::from_utf16_lossy(music);
assert_eq!(string.as_str(), "๐music");
let invalid_utf16 = [0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063];
assert_eq!(SmallString::from_utf16_lossy(invalid_utf16).as_str(), "๐mu\u{FFFD}ic");
let out_of_bounds: Vec<u16> = (0..300).map(|_| 0).collect();
assert_eq!(SmallString::from_utf16_lossy(&out_of_bounds).as_str(),
"\0".repeat(SmallString::capacity().into()).as_str());
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Extracts a string slice containing the entire ArrayString
let s = SmallString::try_from_str("My String")?;
assert_eq!(s.as_str(), "My String");
Sourcepub fn as_mut_str(&mut self) -> &mut str
pub fn as_mut_str(&mut self) -> &mut str
Extracts a mutable string slice containing the entire ArrayString
let mut s = SmallString::try_from_str("My String")?;
assert_eq!(s.as_mut_str(), "My String");
Sourcepub fn as_bytes(&self) -> &[u8] โ
pub fn as_bytes(&self) -> &[u8] โ
Extracts a byte slice containing the entire ArrayString
let s = SmallString::try_from_str("My String")?;
assert_eq!(s.as_bytes(), "My String".as_bytes());
Sourcepub unsafe fn as_mut_bytes(&mut self) -> &mut [u8] โ
pub unsafe fn as_mut_bytes(&mut self) -> &mut [u8] โ
Extracts a mutable string slice containing the entire ArrayString
let mut s = SmallString::try_from_str("My String")?;
assert_eq!(unsafe { s.as_mut_bytes() }, "My String".as_bytes());
Sourcepub fn capacity() -> u8
pub fn capacity() -> u8
Returns maximum string capacity, defined at compile time, it will never change
assert_eq!(ArrayString::<typenum::U32>::capacity(), 32);
Sourcepub fn try_push_str<S>(&mut self, string: S) -> Result<(), OutOfBounds>
pub fn try_push_str<S>(&mut self, string: S) -> Result<(), OutOfBounds>
Pushes string slice to the end of the ArrayString
if total size is lower or equal to capacity
, otherwise returns an error.
let mut s = MaxString::try_from_str("My String")?;
s.try_push_str(" My other String")?;
assert_eq!(s.as_str(), "My String My other String");
assert!(s.try_push_str("0".repeat(MaxString::capacity().into())).is_err());
Sourcepub fn push_str<S>(&mut self, string: S)
pub fn push_str<S>(&mut self, string: S)
Pushes string slice to the end of the ArrayString
truncating total size if bigger than capacity
.
let mut s = MaxString::try_from_str("My String")?;
s.push_str(" My other String");
assert_eq!(s.as_str(), "My String My other String");
let mut s = SmallString::default();
s.push_str("0".repeat(SmallString::capacity() as usize + 1));
assert_eq!(s.as_str(), "0".repeat(SmallString::capacity().into()).as_str());
Sourcepub unsafe fn push_str_unchecked<S>(&mut self, string: S)
pub unsafe fn push_str_unchecked<S>(&mut self, string: S)
Pushes string slice to the end of the ArrayString
assuming total size is appropriate.
ยงSafety
Itโs UB if self.len() + string.len()
> capacity
.
let mut s = MaxString::try_from_str("My String")?;
unsafe { s.push_str_unchecked(" My other String") };
assert_eq!(s.as_str(), "My String My other String");
// Undefined behavior, don't do it
// let mut undefined_behavior = SmallString::default();
// undefined_behavior.push_str_unchecked("0".repeat(SmallString::capacity().into() + 1));
Sourcepub fn try_push(&mut self, character: char) -> Result<(), OutOfBounds>
pub fn try_push(&mut self, character: char) -> Result<(), OutOfBounds>
Inserts character to the end of the ArrayString
erroring if total size if bigger than capacity
.
let mut s = SmallString::try_from_str("My String")?;
s.try_push('!')?;
assert_eq!(s.as_str(), "My String!");
let mut s = SmallString::try_from_str(&"0".repeat(SmallString::capacity().into()))?;
assert!(s.try_push('!').is_err());
Sourcepub unsafe fn push_unchecked(&mut self, ch: char)
pub unsafe fn push_unchecked(&mut self, ch: char)
Inserts character to the end of the ArrayString
assuming length is appropriate
ยงSafety
Itโs UB if self.len() + character.len_utf8()
> capacity
let mut s = SmallString::try_from_str("My String")?;
unsafe { s.push_unchecked('!') };
assert_eq!(s.as_str(), "My String!");
// s = SmallString::try_from_str(&"0".repeat(SmallString::capacity().into()))?;
// Undefined behavior, don't do it
// s.push_unchecked('!');
Sourcepub fn truncate(&mut self, size: u8) -> Result<(), Utf8>
pub fn truncate(&mut self, size: u8) -> Result<(), Utf8>
Truncates ArrayString
to specified size (if smaller than current size and a valid utf-8 char index).
let mut s = SmallString::try_from_str("My String")?;
s.truncate(5)?;
assert_eq!(s.as_str(), "My St");
// Does nothing
s.truncate(6)?;
assert_eq!(s.as_str(), "My St");
// Index is not at a valid char
let mut s = SmallString::try_from_str("๐ค")?;
assert!(s.truncate(1).is_err());
Sourcepub fn pop(&mut self) -> Option<char>
pub fn pop(&mut self) -> Option<char>
Removes last character from ArrayString
, if any.
let mut s = SmallString::try_from_str("A๐ค")?;
assert_eq!(s.pop(), Some('๐ค'));
assert_eq!(s.pop(), Some('A'));
assert_eq!(s.pop(), None);
Sourcepub fn trim(&mut self)
pub fn trim(&mut self)
Removes spaces from the beggining and end of the string
let mut string = MaxString::try_from_str(" to be trimmed ")?;
string.trim();
assert_eq!(string.as_str(), "to be trimmed");
let mut string = SmallString::try_from_str(" ๐ค")?;
string.trim();
assert_eq!(string.as_str(), "๐ค");
Sourcepub fn remove(&mut self, idx: u8) -> Result<char, Error>
pub fn remove(&mut self, idx: u8) -> Result<char, Error>
Removes specified char from ArrayString
let mut s = SmallString::try_from_str("ABCD๐ค")?;
assert_eq!(s.remove("ABCD๐ค".len() as u8), Err(Error::OutOfBounds));
assert_eq!(s.remove(10), Err(Error::OutOfBounds));
assert_eq!(s.remove(6), Err(Error::Utf8));
assert_eq!(s.remove(0), Ok('A'));
assert_eq!(s.as_str(), "BCD๐ค");
assert_eq!(s.remove(2), Ok('D'));
assert_eq!(s.as_str(), "BC๐ค");
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the characters specified by the predicate.
let mut s = SmallString::try_from_str("ABCD๐ค")?;
s.retain(|c| c != '๐ค');
assert_eq!(s.as_str(), "ABCD");
Sourcepub fn try_insert(&mut self, idx: u8, ch: char) -> Result<(), Error>
pub fn try_insert(&mut self, idx: u8, ch: char) -> Result<(), Error>
Inserts character at specified index, returning error if total length is bigger than capacity
.
Returns OutOfBounds
if idx
is out of bounds and Utf8
if idx
is not a char position
let mut s = SmallString::try_from_str("ABCD๐ค")?;
s.try_insert(1, 'A')?;
s.try_insert(2, 'B')?;
assert_eq!(s.as_str(), "AABBCD๐ค");
assert_eq!(s.try_insert(20, 'C'), Err(Error::OutOfBounds));
assert_eq!(s.try_insert(8, 'D'), Err(Error::Utf8));
let mut s = SmallString::try_from_str(&"0".repeat(SmallString::capacity().into()))?;
assert_eq!(s.try_insert(0, 'C'), Err(Error::OutOfBounds));
Sourcepub unsafe fn insert_unchecked(&mut self, idx: u8, ch: char)
pub unsafe fn insert_unchecked(&mut self, idx: u8, ch: char)
Inserts character at specified index assuming length is appropriate
ยงSafety
Itโs UB if idx
does not lie on a utf-8 char
boundary
Itโs UB if self.len() + character.len_utf8()
> capacity
let mut s = SmallString::try_from_str("ABCD๐ค")?;
unsafe { s.insert_unchecked(1, 'A') };
unsafe { s.insert_unchecked(1, 'B') };
assert_eq!(s.as_str(), "ABABCD๐ค");
// Undefined behavior, don't do it
// s.insert(20, 'C');
// s.insert(8, 'D');
Sourcepub fn try_insert_str<S>(&mut self, idx: u8, s: S) -> Result<(), Error>
pub fn try_insert_str<S>(&mut self, idx: u8, s: S) -> Result<(), Error>
Inserts string slice at specified index, returning error if total length is bigger than capacity
.
Returns OutOfBounds
if idx
is out of bounds
Returns Utf8
if idx
is not a char position
let mut s = SmallString::try_from_str("ABCD๐ค")?;
s.try_insert_str(1, "AB")?;
s.try_insert_str(1, "BC")?;
assert_eq!(s.try_insert_str(1, "0".repeat(SmallString::capacity().into())),
Err(Error::OutOfBounds));
assert_eq!(s.as_str(), "ABCABBCD๐ค");
assert_eq!(s.try_insert_str(20, "C"), Err(Error::OutOfBounds));
assert_eq!(s.try_insert_str(10, "D"), Err(Error::Utf8));
Sourcepub fn insert_str<S>(&mut self, idx: u8, string: S) -> Result<(), Error>
pub fn insert_str<S>(&mut self, idx: u8, string: S) -> Result<(), Error>
Inserts string slice at specified index, truncating size if bigger than capacity
.
Returns OutOfBounds
if idx
is out of bounds and Utf8
if idx
is not a char position
let mut s = SmallString::try_from_str("ABCD๐ค")?;
s.insert_str(1, "AB")?;
s.insert_str(1, "BC")?;
assert_eq!(s.as_str(), "ABCABBCD๐ค");
assert_eq!(s.insert_str(20, "C"), Err(Error::OutOfBounds));
assert_eq!(s.insert_str(10, "D"), Err(Error::Utf8));
s.clear();
s.insert_str(0, "0".repeat(SmallString::capacity() as usize + 10))?;
assert_eq!(s.as_str(), "0".repeat(SmallString::capacity().into()).as_str());
Sourcepub unsafe fn insert_str_unchecked<S>(&mut self, idx: u8, string: S)
pub unsafe fn insert_str_unchecked<S>(&mut self, idx: u8, string: S)
Inserts string slice at specified index, assuming total length is appropriate.
ยงSafety
Itโs UB if idx
does not lie on a utf-8 char
boundary
Itโs UB if self.len() + string.len()
> capacity
let mut s = SmallString::try_from_str("ABCD๐ค")?;
unsafe { s.insert_str_unchecked(1, "AB") };
unsafe { s.insert_str_unchecked(1, "BC") };
assert_eq!(s.as_str(), "ABCABBCD๐ค");
// Undefined behavior, don't do it
// unsafe { s.insert_str_unchecked(20, "C") };
// unsafe { s.insert_str_unchecked(10, "D") };
// unsafe { s.insert_str_unchecked(1, "0".repeat(SmallString::capacity().into())) };
Sourcepub fn len(&self) -> u8
pub fn len(&self) -> u8
Returns ArrayString
length.
let mut s = SmallString::try_from_str("ABCD")?;
assert_eq!(s.len(), 4);
s.try_push('๐ค')?;
// Emojis use 4 bytes (this is the default rust behavior, length of u8)
assert_eq!(s.len(), 8);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if ArrayString
is empty.
let mut s = SmallString::try_from_str("ABCD")?;
assert!(!s.is_empty());
s.clear();
assert!(s.is_empty());
Sourcepub fn split_off(&mut self, at: u8) -> Result<ArrayString<SIZE>, Error>
pub fn split_off(&mut self, at: u8) -> Result<ArrayString<SIZE>, Error>
Splits ArrayString
in two if at
is smaller than self.len()
.
Returns Utf8
if at
does not lie at a valid utf-8 char boundary and OutOfBounds
if itโs out of bounds
let mut s = SmallString::try_from_str("AB๐คCD")?;
assert_eq!(s.split_off(6)?.as_str(), "CD");
assert_eq!(s.as_str(), "AB๐ค");
assert_eq!(s.split_off(20), Err(Error::OutOfBounds));
assert_eq!(s.split_off(4), Err(Error::Utf8));
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Empties ArrayString
let mut s = SmallString::try_from_str("ABCD")?;
assert!(!s.is_empty());
s.clear();
assert!(s.is_empty());
Sourcepub fn drain<R>(&mut self, range: R) -> Result<Drain<SIZE>, Error>where
R: RangeBounds<u8>,
pub fn drain<R>(&mut self, range: R) -> Result<Drain<SIZE>, Error>where
R: RangeBounds<u8>,
Creates a draining iterator that removes the specified range in the ArrayString
and yields the removed chars.
Note: The element range is removed even if the iterator is not consumed until the end.
let mut s = SmallString::try_from_str("ABCD๐ค")?;
assert_eq!(s.drain(..3)?.collect::<Vec<_>>(), vec!['A', 'B', 'C']);
assert_eq!(s.as_str(), "D๐ค");
assert_eq!(s.drain(3..), Err(Error::Utf8));
assert_eq!(s.drain(10..), Err(Error::OutOfBounds));
Sourcepub fn replace_range<S, R>(&mut self, r: R, with: S) -> Result<(), Error>
pub fn replace_range<S, R>(&mut self, r: R, with: S) -> Result<(), Error>
Removes the specified range of the ArrayString
, and replaces it with the given string. The given string doesnโt need to have the same length as the range.
let mut s = SmallString::try_from_str("ABCD๐ค")?;
s.replace_range(2..4, "EFGHI")?;
assert_eq!(s.as_str(), "ABEFGHI๐ค");
assert_eq!(s.replace_range(9.., "J"), Err(Error::Utf8));
assert_eq!(s.replace_range(..90, "K"), Err(Error::OutOfBounds));
assert_eq!(s.replace_range(0..1, "0".repeat(SmallString::capacity().into())),
Err(Error::OutOfBounds));
Trait Implementations
Sourceยงimpl<'a, SIZE> Add<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<'a, SIZE> Add<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> AsMut<str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> AsMut<str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> AsRef<[u8]> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> AsRef<[u8]> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> AsRef<str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> AsRef<str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> Borrow<str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Borrow<str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> BorrowMut<str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> BorrowMut<str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn borrow_mut(&mut self) -> &mut str
fn borrow_mut(&mut self) -> &mut str
Sourceยงimpl<SIZE> Clone for ArrayString<SIZE>
impl<SIZE> Clone for ArrayString<SIZE>
Sourceยงfn clone(&self) -> ArrayString<SIZE>
fn clone(&self) -> ArrayString<SIZE>
1.0.0 ยท Sourceยงconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSourceยงimpl<SIZE> Debug for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Debug for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> Default for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Default for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn default() -> ArrayString<SIZE>
fn default() -> ArrayString<SIZE>
Sourceยงimpl<SIZE> Deref for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Deref for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> DerefMut for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> DerefMut for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> Display for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Display for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<'a, SIZE> Extend<&'a char> for ArrayString<SIZE>where
SIZE: Capacity,
impl<'a, SIZE> Extend<&'a char> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a char>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = &'a char>,
Sourceยงfn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Sourceยงfn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Sourceยงimpl<'a, SIZE> Extend<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<'a, SIZE> Extend<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = &'a str>,
fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = &'a str>,
Sourceยงfn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Sourceยงfn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Sourceยงimpl<SIZE> Extend<char> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Extend<char> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = char>,
fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = char>,
Sourceยงfn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Sourceยงfn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Sourceยงimpl<'a, SIZE> From<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<'a, SIZE> From<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn from(s: &str) -> ArrayString<SIZE>
fn from(s: &str) -> ArrayString<SIZE>
Sourceยงimpl<'a, SIZE> FromIterator<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
impl<'a, SIZE> FromIterator<&'a str> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn from_iter<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = &'a str>,
fn from_iter<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = &'a str>,
Sourceยงimpl<SIZE> FromIterator<char> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> FromIterator<char> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn from_iter<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = char>,
fn from_iter<I>(iter: I) -> ArrayString<SIZE>where
I: IntoIterator<Item = char>,
Sourceยงimpl<SIZE> FromStr for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> FromStr for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงtype Err = OutOfBounds
type Err = OutOfBounds
Sourceยงfn from_str(
s: &str,
) -> Result<ArrayString<SIZE>, <ArrayString<SIZE> as FromStr>::Err>
fn from_str( s: &str, ) -> Result<ArrayString<SIZE>, <ArrayString<SIZE> as FromStr>::Err>
s
to return a value of this type. Read moreSourceยงimpl<SIZE> Hash for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Hash for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> Index<RangeFull> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Index<RangeFull> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงimpl<SIZE> Index<RangeInclusive<u8>> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Index<RangeInclusive<u8>> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn index(
&self,
index: RangeInclusive<u8>,
) -> &<ArrayString<SIZE> as Index<RangeInclusive<u8>>>::Output
fn index( &self, index: RangeInclusive<u8>, ) -> &<ArrayString<SIZE> as Index<RangeInclusive<u8>>>::Output
container[index]
) operation. Read moreSourceยงimpl<SIZE> Index<RangeToInclusive<u8>> for ArrayString<SIZE>where
SIZE: Capacity,
impl<SIZE> Index<RangeToInclusive<u8>> for ArrayString<SIZE>where
SIZE: Capacity,
Sourceยงfn index(
&self,
index: RangeToInclusive<u8>,
) -> &<ArrayString<SIZE> as Index<RangeToInclusive<u8>>>::Output
fn index( &self, index: RangeToInclusive<u8>, ) -> &<ArrayString<SIZE> as Index<RangeToInclusive<u8>>>::Output
container[index]
) operation. Read more