[−][src]Struct staticvec::StaticString
A fixed-capacity String
-like struct built around an instance of
StaticVec<u8, N>
.
Examples
use staticvec::{StaticString, StringError}; #[derive(Debug)] pub struct User { pub username: StaticString<20>, pub role: StaticString<5>, } fn main() -> Result<(), StringError> { let user = User { username: StaticString::try_from_str("user")?, role: StaticString::try_from_str("admin")?, }; println!("{:?}", user); Ok(()) }
Implementations
impl<const N: usize> StaticString<N>
[src]
pub fn new() -> Self
[src]
Returns a new StaticString instance.
Example usage:
let string = StaticString::<20>::new(); assert!(string.is_empty());
pub unsafe fn from_str_unchecked(string: &str) -> Self
[src]
Creates a new StaticString instance from string
, without doing any checking to ensure that
the length of string
does not exceed the resulting StaticString's declared capacity.
Safety
The length of string
must not exceed the declared capacity of the StaticString being
created, as this would result in writing to an out-of-bounds memory region.
Example usage:
let string = unsafe { StaticString::<20>::from_str_unchecked("My String") }; assert_eq!(string, "My String");
pub fn from_str<S: AsRef<str>>(string: S) -> Self
[src]
Creates a new StaticString from string
, truncating string
as necessary if it has
a length greater than the StaticString's declared capacity.
Example usage:
let string = StaticString::<20>::from_str("My String"); assert_eq!(string, "My String"); let truncate = "0".repeat(21); let truncated = "0".repeat(20); let string = StaticString::<20>::from_str(&truncate); assert_eq!(string, truncated.as_str());
pub fn try_from_str<S: AsRef<str>>(string: S) -> Result<Self, CapacityError<N>>
[src]
Creates a new StaticString from string
if the length of string
is less than or equal
to the StaticString's declared capacity, or returns a
CapacityError
otherwise.
Example usage:
let string = StaticString::<20>::from("My String"); assert_eq!(string.as_str(), "My String"); assert_eq!(StaticString::<20>::try_from_str("").unwrap().as_str(), ""); let out_of_bounds = "0".repeat(21); assert!(StaticString::<20>::try_from_str(out_of_bounds).is_err());
pub fn from_iterator<U: AsRef<str>, I: IntoIterator<Item = U>>(iter: I) -> Self
[src]
Creates a new StaticString from the contents of an iterator, returning immediately if and when the StaticString reaches maximum capacity regardless of whether or not the iterator still has more items to yield.
Example usage:
let string = StaticString::<300>::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(18); let truncate = StaticString::<20>::from_iterator(out_of_bounds); assert_eq!(truncate.as_str(), truncated.as_str());
pub fn try_from_iterator<U: AsRef<str>, I: IntoIterator<Item = U>>(
iter: I
) -> Result<Self, CapacityError<N>>
[src]
iter: I
) -> Result<Self, CapacityError<N>>
Creates a new StaticString from the contents of an iterator if the iterator has a length less
than or equal to the StaticString's declared capacity, or returns a
CapacityError
otherwise.
Example usage:
let string = StaticString::<300>::try_from_iterator( &["My String", " My Other String"][..] ).unwrap(); assert_eq!(string.as_str(), "My String My Other String"); let out_of_bounds = (0..100).map(|_| "000"); assert!(StaticString::<20>::try_from_iterator(out_of_bounds).is_err());
pub fn from_chars<I: IntoIterator<Item = char>>(iter: I) -> Self
[src]
Creates a new StaticString from the contents of a char
iterator, returning immediately if
and when the StaticString reaches maximum capacity regardless of whether or not the iterator
still has more items to yield.
let string = StaticString::<20>::from_chars("My String".chars()); assert_eq!(string, "My String"); let out_of_bounds = "0".repeat(21); let truncated = "0".repeat(20); let truncate = StaticString::<20>::from_chars(out_of_bounds.chars()); assert_eq!(truncate.as_str(), truncated.as_str());
pub fn try_from_chars<I: IntoIterator<Item = char>>(
iter: I
) -> Result<Self, StringError>
[src]
iter: I
) -> Result<Self, StringError>
Creates a new StaticString from the contents of a char
iterator if the iterator has a length
less than or equal to the StaticString's declared capacity, or returns
StringError::OutOfBounds
otherwise.
Example usage:
let string = StaticString::<20>::try_from_chars("My String".chars())?; assert_eq!(string.as_str(), "My String"); let out_of_bounds = "0".repeat(21); assert!(StaticString::<20>::try_from_chars(out_of_bounds.chars()).is_err());
pub unsafe fn from_utf8_unchecked<B: AsRef<[u8]>>(slice: B) -> Self
[src]
Creates a new StaticString instance from the provided byte slice, without doing any checking to ensure that the slice contains valid UTF-8 data and has a length less than or equal to the declared capacity of the StaticString.
Safety
The length of the slice must not exceed the declared capacity of the StaticString being created, as this would result in writing to an out-of-bounds memory region.
The slice must also contain strictly valid UTF-8 data, as if it does not, various assumptions made in the internal implementation of StaticString will be silently invalidated, almost certainly eventually resulting in undefined behavior.
Example usage:
let string = unsafe { StaticString::<20>::from_utf8_unchecked("My String") }; assert_eq!(string, "My String"); // Undefined behavior, don't do it: // let out_of_bounds = "0".repeat(300); // let ub = unsafe { StaticString::<20>::from_utf8_unchecked(out_of_bounds)) };
pub fn from_utf8<B: AsRef<[u8]>>(slice: B) -> Result<Self, StringError>
[src]
Creates a new StaticString instance from the provided byte slice, returning
StringError::Utf8
on invalid UTF-8 data, and truncating the input slice as necessary if
it has a length greater than the declared capacity of the StaticString being created.
Example usage:
let string = StaticString::<20>::from_utf8("My String")?; assert_eq!(string, "My String"); let invalid_utf8 = [0, 159, 146, 150]; assert!(StaticString::<20>::from_utf8(invalid_utf8).unwrap_err().is_utf8()); let out_of_bounds = "0".repeat(300); assert_eq!(StaticString::<20>::from_utf8(out_of_bounds.as_bytes())?.as_str(), "0".repeat(20).as_str());
pub fn try_from_utf8<B: AsRef<[u8]>>(slice: B) -> Result<Self, StringError>
[src]
Creates a new StaticString from the provided byte slice, returning StringError::Utf8
on
invalid UTF-8 data or StringError::OutOfBounds
if the slice has a length greater than
the StaticString's declared capacity.
Example usage:
let string = StaticString::<20>::try_from_utf8("My String")?; assert_eq!(string, "My String"); let invalid_utf8 = [0, 159, 146, 150]; assert!(StaticString::<20>::try_from_utf8(invalid_utf8).unwrap_err().is_utf8()); let out_of_bounds = "0000".repeat(400); assert!(StaticString::<20>::try_from_utf8(out_of_bounds.as_bytes()).unwrap_err().is_out_of_bounds());
pub fn from_utf16_lossy<B: AsRef<[u16]>>(slice: B) -> Self
[src]
Creates a new StaticString instance from the provided u16
slice, replacing invalid UTF-16
data with REPLACEMENT_CHARACTER
(�), and truncating the input slice as necessary if
it has a length greater than the declared capacity of the StaticString being created.
Example usage:
let music = [0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0x0069, 0x0063]; let string = StaticString::<20>::from_utf16_lossy(music); assert_eq!(string, "𝄞music"); let invalid_utf16 = [0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063]; assert_eq!(StaticString::<20>::from_utf16_lossy(invalid_utf16).as_str(), "𝄞mu\u{FFFD}ic"); let out_of_bounds: Vec<u16> = (0..300).map(|_| 0).collect(); assert_eq!(StaticString::<20>::from_utf16_lossy(&out_of_bounds).as_str(), "\0".repeat(20).as_str());
pub fn from_utf16<B: AsRef<[u16]>>(slice: B) -> Result<Self, StringError>
[src]
Creates a new StaticString instance from the provided u16
slice, returning
StringError::Utf16
on invalid UTF-16 data, and truncating the input slice as necessary if
it has a length greater than the declared capacity of the StaticString being created.
Example usage:
let music = [0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0x0069, 0x0063]; let string = StaticString::<20>::from_utf16(music)?; assert_eq!(string.as_str(), "𝄞music"); let invalid_utf16 = [0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063]; assert!(StaticString::<20>::from_utf16(invalid_utf16).unwrap_err().is_utf16()); let out_of_bounds: Vec<u16> = (0..300).map(|_| 0).collect(); assert_eq!(StaticString::<20>::from_utf16(out_of_bounds)?.as_str(), "\0".repeat(20).as_str());
pub fn try_from_utf16<B: AsRef<[u16]>>(slice: B) -> Result<Self, StringError>
[src]
Creates a new StaticString from the provided u16
slice, returning StringError::Utf16
on
invalid UTF-16 data or StringError::OutOfBounds
if the slice has a length greater than the
declared capacity of the StaticString being created.
Example usage:
let music = [0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0x0069, 0x0063]; let string = StaticString::<20>::try_from_utf16(music)?; assert_eq!(string.as_str(), "𝄞music"); let invalid_utf16 = [0xD834, 0xDD1E, 0x006d, 0x0075, 0xD800, 0x0069, 0x0063]; assert!(StaticString::<20>::try_from_utf16(invalid_utf16).unwrap_err().is_utf16()); let out_of_bounds: StaticVec<u16, 300> = (0..300).map(|_| 0).collect(); assert!(StaticString::<20>::try_from_utf16(out_of_bounds).unwrap_err().is_out_of_bounds());
pub fn as_str(&self) -> &str
[src]
Extracts a str
slice containing the entire contents of the StaticString.
Example usage:
let s = StaticString::<20>::from_str("My String"); assert_eq!(s.as_str(), "My String");
pub fn as_mut_str(&mut self) -> &mut str
[src]
Extracts a mutable str
slice containing the entire contents of the StaticString.
Example usage:
let mut s = StaticString::<20>::from_str("My String"); assert_eq!(s.as_mut_str(), "My String");
pub fn as_bytes(&self) -> &[u8]
[src]
Extracts a u8
slice containing the entire contents of the StaticString.
Example usage:
let s = StaticString::<20>::from_str("My String"); assert_eq!(s.as_bytes(), "My String".as_bytes());
pub fn into_bytes(self) -> StaticVec<u8, N>ⓘ
[src]
Returns the StaticString's internal instance of StaticVec<u8, N>
.
Note that using this function consumes the StaticString.
Example usage:
let s = StaticString::<5>::from("hello"); let bytes = s.into_bytes(); assert_eq!(&bytes[..], &[104, 101, 108, 108, 111][..]);
pub unsafe fn as_mut_bytes(&mut self) -> &mut [u8]
[src]
Extracts a mutable u8
slice containing the entire contents of the StaticString.
Safety
Care must be taken to ensure that the returned u8
slice is not mutated in such a way that
it no longer amounts to valid UTF-8.
Example usage:
let mut s = StaticString::<20>::try_from_str("My String")?; assert_eq!(unsafe { s.as_mut_bytes() }, "My String".as_bytes());
pub unsafe fn as_mut_staticvec(&mut self) -> &mut StaticVec<u8, N>ⓘ
[src]
Returns a mutable reference to the StaticString's backing StaticVec.
Safety
Care must be taken to ensure that the returned StaticVec reference is not mutated in such a way that it no longer contains valid UTF-8.
Example usage:
let mut s = StaticString::<20>::try_from_str("My String")?; assert_eq!(unsafe { s.as_mut_staticvec() }, "My String".as_bytes());
pub fn capacity(&self) -> usize
[src]
Returns the total capacity of the StaticString.
This is always equivalent to the generic N
parameter it was declared with,
which determines the fixed size of the backing StaticVec instance.
Example usage:
assert_eq!(StaticString::<32>::new().capacity(), 32);
pub fn remaining_capacity(&self) -> usize
[src]
Returns the remaining capacity (which is to say, self.capacity() - self.len()
) of the
StaticString.
Example usage:
assert_eq!(StaticString::<32>::from("abcd").remaining_capacity(), 28);
pub unsafe fn push_str_unchecked(&mut self, string: &str)
[src]
Pushes string
to the StaticString without doing any checking to ensure that self.len() + string.len()
does not exceed the StaticString's total capacity.
Safety
self.len() + string.len()
must not exceed the total capacity of the StaticString
instance, as this would result in writing to an out-of-bounds memory region.
Example usage:
let mut s = StaticString::<6>::from("foo"); unsafe { s.push_str_unchecked("bar") }; assert_eq!(s, "foobar");
pub fn push_str<S: AsRef<str>>(&mut self, string: S)
[src]
Attempts to push string
to the StaticString, panicking if it is the case that self.len() + string.len()
exceeds the StaticString's total capacity.
Example usage:
let mut s = StaticString::<6>::from("foo"); s.push_str("bar"); assert_eq!(s, "foobar");
pub fn push_str_truncating<S: AsRef<str>>(&mut self, string: S)
[src]
Attempts to push string
to the StaticString. Truncates string
as necessary (or simply does
nothing at all) if it is the case that self.len() + string.len()
exceeds the
StaticString's total capacity.
Example usage:
let mut s = StaticString::<300>::try_from_str("My String")?; s.push_str_truncating(" My other String"); assert_eq!(s.as_str(), "My String My other String"); let mut s = StaticString::<20>::new(); s.push_str_truncating("0".repeat(21)); assert_eq!(s.as_str(), "0".repeat(20).as_str());
pub fn try_push_str<S: AsRef<str>>(
&mut self,
string: S
) -> Result<(), CapacityError<N>>
[src]
&mut self,
string: S
) -> Result<(), CapacityError<N>>
Pushes string
to the StaticString if self.len() + string.len()
does not exceed
the StaticString's total capacity, or returns a
CapacityError
otherwise.
Example usage:
let mut s = StaticString::<300>::from("My String"); s.try_push_str(" My other String").unwrap(); assert_eq!(s.as_str(), "My String My other String"); assert!(s.try_push_str("0".repeat(300)).is_err());
pub unsafe fn push_unchecked(&mut self, character: char)
[src]
Appends the given char to the end of the StaticString without doing any checking to ensure
that self.len() + character.len_utf8()
does not exceed the total capacity of the
StaticString instance.
Safety
self.len() + character.len_utf8()
must not exceed the total capacity of the StaticString
instance, as this would result in writing to an out-of-bounds memory region.
Example usage:
let mut s = StaticString::<20>::try_from_str("My String")?; unsafe { s.push_unchecked('!') }; assert_eq!(s.as_str(), "My String!"); // Undefined behavior, don't do it: // s = StaticString::<20>::try_from_str(&"0".repeat(20))?; // s.push_unchecked('!');
pub fn push(&mut self, character: char)
[src]
Appends the given char to the end of the StaticString, panicking if the StaticString is already at maximum capacity.
Example usage:
let mut string = StaticString::<2>::new(); string.push('a'); string.push('b'); assert_eq!(&string[..], "ab");
pub fn try_push(&mut self, character: char) -> Result<(), StringError>
[src]
Appends the given char to the end of the StaticString, returning StringError::OutOfBounds
if the StaticString is already at maximum capacity.
Example usage:
let mut s = StaticString::<20>::try_from_str("My String")?; s.try_push('!')?; assert_eq!(s.as_str(), "My String!"); let mut s = StaticString::<20>::try_from_str(&"0".repeat(20))?; assert!(s.try_push('!').is_err());
pub fn truncate(&mut self, new_len: usize)
[src]
Truncates the StaticString to new_len
if new_len
is less than or equal to the
StaticString's current length, or does nothing otherwise. Panics if new_len
does not lie
at a valid UTF-8 character boundary.
Example usage:
let mut s = StaticString::<20>::from("My String"); s.truncate(5); assert_eq!(s, "My St"); // Does nothing s.truncate(6); assert_eq!(s, "My St"); // Would panic // let mut s2 = StaticString::<20>::from("🤔"); // s2.truncate(1);
pub fn pop(&mut self) -> Option<char>
[src]
Returns the last character in the StaticString in Some
if the StaticString's current length
is greater than zero, or None
otherwise.
Example usage:
let mut s = StaticString::<20>::try_from_str("A🤔")?; assert_eq!(s.pop(), Some('🤔')); assert_eq!(s.pop(), Some('A')); assert_eq!(s.pop(), None);
pub fn trim(&mut self)
[src]
Removes all whitespace from the beginning and end of the StaticString, if any is present.
Example usage:
let mut string = StaticString::<300>::try_from_str(" to be trimmed ")?; string.trim(); assert_eq!(string.as_str(), "to be trimmed"); let mut string = StaticString::<20>::try_from_str(" 🤔")?; string.trim(); assert_eq!(string.as_str(), "🤔");
pub fn remove(&mut self, index: usize) -> char
[src]
Removes the char at index
from the StaticString if index
is both less than self.len()
and also lies at a valid UTF-8 character boundary, or panics otherwise.
Example usage:
let mut s = StaticString::<20>::from("ABCD🤔"); assert_eq!(s.remove(0), 'A'); assert!(s == "BCD🤔"); assert_eq!(s.remove(2), 'D'); assert!(s == "BC🤔");
pub fn retain<F: FnMut(char) -> bool>(&mut self, f: F)
[src]
Removes all characters from the StaticString except for those specified by the predicate function.
Example usage:
let mut s = StaticString::<20>::from("ABCD🤔"); s.retain(|c| c != '🤔'); assert_eq!(s, "ABCD");
pub unsafe fn insert_unchecked(&mut self, index: usize, character: char)
[src]
Inserts character
at index
, shifting any values that exist in positions greater than
index
to the right.
Does not do any checking to ensure that character.len_utf8() + self.len()
does not exceed
the total capacity of the StaticString or that index
lies at a valid UTF-8 character
boundary.
Safety
The length of the StaticString prior to calling this function must be less than its total capacity, as if this in not the case it will result in writing to an out-of-bounds memory region.
Index
must also lie at a valid UTF-8 character boundary, as if it does not, various
assumptions made in the internal implementation of StaticString will be silently
invalidated, almost certainly eventually resulting in undefined behavior.
Example usage:
let mut s = StaticString::<20>::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');
pub fn try_insert(
&mut self,
index: usize,
character: char
) -> Result<(), StringError>
[src]
&mut self,
index: usize,
character: char
) -> Result<(), StringError>
Inserts character
at index
, shifting any values that exist in positions greater than
index
to the right.
Returns StringError::OutOfBounds
if character.len_utf8() + self.len()
exceeds the total
capacity of the StaticString and StringError::NotCharBoundary
if index
does not lie at
a valid UTF-8 character boundary.
Example usage:
let mut s = StaticString::<20>::try_from_str("ABCD🤔")?; s.try_insert(1, 'E')?; s.try_insert(2, 'F')?; assert_eq!(s.as_str(), "AEFBCD🤔"); assert!(s.try_insert(20, 'C').unwrap_err().is_not_char_boundary()); assert!(s.try_insert(8, 'D').unwrap_err().is_not_char_boundary()); let mut s = StaticString::<20>::try_from_str(&"0".repeat(20))?; assert!(s.try_insert(0, 'C').unwrap_err().is_out_of_bounds());
pub fn insert(&mut self, index: usize, character: char)
[src]
Inserts character
at index
, shifting any values that exist in positions greater than
index
to the right.
Panics if character.len_utf8() + self.len()
exceeds the total capacity of the StaticString
or if index
does not lie at a valid UTF-8 character boundary.
Example usage:
let mut s = StaticString::<3>::new(); s.insert(0, 'f'); s.insert(1, 'o'); s.insert(2, 'o'); assert_eq!(s, "foo");
pub unsafe fn insert_str_unchecked<S: AsRef<str>>(
&mut self,
index: usize,
string: S
)
[src]
&mut self,
index: usize,
string: S
)
Inserts string
at index
, shifting any values that exist in positions greater than
index
to the right.
Does not do any checking to ensure that self.len() + string.len()
does not exceed
the total capacity of the StaticString or that index
lies at a valid UTF-8
character boundary.
Safety
self.len() + string.len()
must not exceed the total capacity of the StaticString instance,
as this would result in writing to an out-of-bounds memory region.
Index
must also lie at a valid UTF-8 character boundary, as if it does not, various
assumptions made in the internal implementation of StaticString will be silently
invalidated, almost certainly eventually resulting in undefined behavior.
Example usage:
let mut s = StaticString::<20>::from_str("ABCD🤔"); unsafe { s.insert_str_unchecked(1, "AB") }; unsafe { s.insert_str_unchecked(1, "BC") }; assert_eq!(s, "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(20)) };
pub fn insert_str<S: AsRef<str>>(&mut self, index: usize, string: S)
[src]
Inserts string
at index
, shifting any values that exist in positions greater than
index
to the right.
Panics if index
is greater than the length of the StaticString or if it does not lie
at a valid UTF-8 character boundary, as well as if string.len() + self.len()
exceeds
the total capacity of the StaticString.
Example usage:
let mut s = StaticString::<20>::from("ABCD🤔"); s.insert_str(1, "AB"); s.insert_str(1, "BC"); assert_eq!(s.as_str(), "ABCABBCD🤔");
pub fn try_insert_str<S: AsRef<str>>(
&mut self,
index: usize,
string: S
) -> Result<(), StringError>
[src]
&mut self,
index: usize,
string: S
) -> Result<(), StringError>
Inserts string
at index
, shifting any values that exist in positions greater than
index
to the right.
Returns StringError::OutOfBounds
if self.len() + string.len()
exceeds the total
capacity of the StaticString and StringError::NotCharBoundary
if index
does not
lie at a valid UTF-8 character boundary.
Example usage:
let mut string = StaticString::<20>::try_from_str("ABCD🤔")?; string.try_insert_str(1, "AB")?; string.try_insert_str(1, "BC")?; assert!(string.try_insert_str(1, "0".repeat(20)).unwrap_err().is_out_of_bounds()); assert_eq!(string.as_str(), "ABCABBCD🤔"); assert!(string.try_insert_str(20, "C").unwrap_err().is_not_char_boundary()); assert!(string.try_insert_str(10, "D").unwrap_err().is_not_char_boundary());
pub fn len(&self) -> usize
[src]
Returns the current length of the StaticString.
Example usage:
let mut s = StaticString::<20>::from("ABCD"); assert_eq!(s.len(), 4); s.push('🤔'); assert_eq!(s.len(), 8);
pub fn is_empty(&self) -> bool
[src]
Returns true if the StaticString has a current length of 0.
Example usage:
let mut s = staticstring!("ABCD"); assert!(!s.is_empty()); s.clear(); assert!(s.is_empty());
pub fn is_full(&self) -> bool
[src]
Returns true if the StaticString's length is equal to its capacity.
Example usage:
let mut s = staticstring!("ABCD"); assert!(s.is_full()); s.clear(); assert!(!s.is_full());
pub fn split_off(&mut self, at: usize) -> Self
[src]
Splits the StaticString in two if at
is less than the its current length.
The original StaticString will contain elements 0..at
, and the new one will contain
elements at..self.len()
.
Panics if at
is greater than the length of the StaticString or if it does not
lie at a valid UTF-8 character boundary.
Example usage:
let mut ab = StaticString::<4>::from("ABCD"); let cd = ab.split_off(2); assert_eq!(ab, "AB"); assert_eq!(cd, "CD");
pub fn clear(&mut self)
[src]
Removes all contents from the StaticString and sets its length back to zero.
Example usage:
let mut s = StaticString::<20>::try_from_str("ABCD")?; assert!(!s.is_empty()); s.clear(); assert!(s.is_empty());
pub fn replace_range<S: AsRef<str>, R: RangeBounds<usize>>(
&mut self,
range: R,
with: S
)
[src]
&mut self,
range: R,
with: S
)
Removes the specified range from the StaticString and replaces it with the provided input
(which does not need to have the same length as the range being removed), panicking if
either the high or low bounds of the range exceed self.len()
or do not lie at valid UTF-8
character boundaries.
Example usage:
let mut s = StaticString::<20>::from("ABCD🤔"); s.replace_range(2..4, "EFGHI"); assert_eq!(s.as_str(), "ABEFGHI🤔");
Trait Implementations
impl<const N: usize, '_> Add<&'_ str> for StaticString<N>
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, other: &str) -> Self::Output
[src]
impl<const N: usize, '_> AddAssign<&'_ str> for StaticString<N>
[src]
fn add_assign(&mut self, other: &str)
[src]
impl<const N: usize> AsMut<str> for StaticString<N>
[src]
impl<const N: usize> AsRef<[u8]> for StaticString<N>
[src]
impl<const N: usize> AsRef<str> for StaticString<N>
[src]
impl<const N: usize> Borrow<str> for StaticString<N>
[src]
impl<const N: usize> BorrowMut<str> for StaticString<N>
[src]
fn borrow_mut(&mut self) -> &mut str
[src]
impl<const N: usize> Clone for StaticString<N>
[src]
fn clone(&self) -> StaticString<N>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<const N: usize> Debug for StaticString<N>
[src]
impl<const N: usize> Default for StaticString<N>
[src]
impl<const N: usize> Deref for StaticString<N>
[src]
impl<const N: usize> DerefMut for StaticString<N>
[src]
impl<const N: usize> Display for StaticString<N>
[src]
impl<const N: usize> Eq for StaticString<N>
[src]
impl<'a, const N: usize> Extend<&'a char> for StaticString<N>
[src]
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
[src]
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<'a, const N: usize> Extend<&'a str> for StaticString<N>
[src]
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iterable: I)
[src]
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<const N: usize> Extend<char> for StaticString<N>
[src]
fn extend<I: IntoIterator<Item = char>>(&mut self, iterable: I)
[src]
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<'a, const N: usize> From<&'a str> for StaticString<N>
[src]
impl<const N: usize> From<StaticString<N>> for StaticVec<u8, N>
[src]
fn from(string: StaticString<N>) -> Self
[src]
impl<const N1: usize, const N2: usize> From<StaticString<N1>> for StaticVec<u8, N2>
[src]
default fn from(string: StaticString<N1>) -> Self
[src]
impl<const N: usize> From<StaticVec<u8, N>> for StaticString<N>
[src]
impl<const N1: usize, const N2: usize> From<StaticVec<u8, N1>> for StaticString<N2>
[src]
impl<const N: usize> From<String> for StaticString<N>
[src]
Note: this is only available when the std
crate feature is enabled.
impl<'a, const N: usize> FromIterator<&'a char> for StaticString<N>
[src]
fn from_iter<I: IntoIterator<Item = &'a char>>(iter: I) -> Self
[src]
impl<'a, const N: usize> FromIterator<&'a str> for StaticString<N>
[src]
fn from_iter<I: IntoIterator<Item = &'a str>>(iter: I) -> Self
[src]
impl<const N: usize> FromIterator<char> for StaticString<N>
[src]
fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> Self
[src]
impl<'a, const N: usize> FromStr for StaticString<N>
[src]
type Err = ()
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl<const N: usize> Hash for StaticString<N>
[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,
impl<const N: usize> Index<Range<usize>> for StaticString<N>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: Range<usize>) -> &Self::Output
[src]
impl<const N: usize> Index<RangeFrom<usize>> for StaticString<N>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeFrom<usize>) -> &Self::Output
[src]
impl<const N: usize> Index<RangeFull> for StaticString<N>
[src]
type Output = str
The returned type after indexing.
fn index(&self, _index: RangeFull) -> &Self::Output
[src]
impl<const N: usize> Index<RangeInclusive<usize>> for StaticString<N>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeInclusive<usize>) -> &Self::Output
[src]
impl<const N: usize> Index<RangeTo<usize>> for StaticString<N>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeTo<usize>) -> &Self::Output
[src]
impl<const N: usize> Index<RangeToInclusive<usize>> for StaticString<N>
[src]
type Output = str
The returned type after indexing.
fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output
[src]
impl<const N: usize> IndexMut<Range<usize>> for StaticString<N>
[src]
impl<const N: usize> IndexMut<RangeFrom<usize>> for StaticString<N>
[src]
impl<const N: usize> IndexMut<RangeFull> for StaticString<N>
[src]
impl<const N: usize> IndexMut<RangeInclusive<usize>> for StaticString<N>
[src]
fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut str
[src]
impl<const N: usize> IndexMut<RangeTo<usize>> for StaticString<N>
[src]
impl<const N: usize> IndexMut<RangeToInclusive<usize>> for StaticString<N>
[src]
fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut str
[src]
impl<const N: usize> Ord for StaticString<N>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<const N: usize, '_> PartialEq<&'_ str> for StaticString<N>
[src]
impl<const N: usize> PartialEq<StaticString<N>> for StaticString<N>
[src]
impl<const N: usize> PartialEq<String> for StaticString<N>
[src]
Note: this is only available when the std
crate feature is enabled.
impl<const N: usize> PartialEq<str> for StaticString<N>
[src]
impl<const N: usize, '_> PartialOrd<&'_ str> for StaticString<N>
[src]
fn partial_cmp(&self, other: &&str) -> 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<const N: usize> PartialOrd<StaticString<N>> for StaticString<N>
[src]
fn partial_cmp(&self, other: &Self) -> 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<const N: usize> PartialOrd<String> for StaticString<N>
[src]
Note: this is only available when the std
crate feature is enabled.
fn partial_cmp(&self, other: &String) -> 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<const N: usize> PartialOrd<str> for StaticString<N>
[src]
fn partial_cmp(&self, other: &str) -> 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<const N: usize> Write for StaticString<N>
[src]
Auto Trait Implementations
impl<const N: usize> RefUnwindSafe for StaticString<N>
impl<const N: usize> Send for StaticString<N>
impl<const N: usize> Sync for StaticString<N>
impl<const N: usize> Unpin for StaticString<N>
impl<const N: usize> UnwindSafe for StaticString<N>
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>,