pub struct ByteStr { /* private fields */ }Expand description
Borrowed reference to a byte string. It provides similar functionality as str
and [u8].
Implementations§
Source§impl ByteStr
impl ByteStr
Sourcepub fn from_slice(bytes: &[u8]) -> &Self
pub fn from_slice(bytes: &[u8]) -> &Self
Creates a ByteStr from a byte slice.
Sourcepub fn from_slice_mut(bytes: &mut [u8]) -> &mut Self
pub fn from_slice_mut(bytes: &mut [u8]) -> &mut Self
Create a mutable ByteStr from a byte slice.
Sourcepub unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a Self
pub unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a Self
Forms a ByteStr from a pointer and a length.
Sourcepub unsafe fn from_raw_parts_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut Self
pub unsafe fn from_raw_parts_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut Self
Forms a mutable ByteStr from a pointer and a length.
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Converts self into a mutable byte slice.
Sourcepub fn to_byte_string(&self) -> ByteString
pub fn to_byte_string(&self) -> ByteString
Copies the self into a ByteString.
Sourcepub fn into_boxed_slice(self: Box<Self>) -> Box<[u8]>
pub fn into_boxed_slice(self: Box<Self>) -> Box<[u8]>
Converts self into a boxed slice without clones or allocation.
Sourcepub fn into_vec(self: Box<Self>) -> Vec<u8> ⓘ
pub fn into_vec(self: Box<Self>) -> Vec<u8> ⓘ
Converts self into a vector without clones or allocation.
Sourcepub fn into_byte_string(self: Box<Self>) -> ByteString
pub fn into_byte_string(self: Box<Self>) -> ByteString
Converts self into a ByteString without clones or allocation.
Sourcepub fn as_ptr(&self) -> *const u8
pub fn as_ptr(&self) -> *const u8
Converts self into a raw pointer that points to the first byte of the string.
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Converts self into a mutable raw pointer that points to the first byte of the string.
Sourcepub fn get(&self, index: usize) -> Option<&u8>
pub fn get(&self, index: usize) -> Option<&u8>
Returns a reference to an element of the slice, or None if the
index is out of bounds.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut u8>
pub fn get_mut(&mut self, index: usize) -> Option<&mut u8>
Returns a mutable reference to an element of the slice, or None if the
index is out of bounds.
Sourcepub fn first(&self) -> Option<&u8>
pub fn first(&self) -> Option<&u8>
Returns a reference to the first byte of the string, or None if it is empty.
Sourcepub fn first_mut(&mut self) -> Option<&mut u8>
pub fn first_mut(&mut self) -> Option<&mut u8>
Returns a mutable reference to the first byte of the string, or None if it is empty.
Sourcepub fn last(&self) -> Option<&u8>
pub fn last(&self) -> Option<&u8>
Returns a reference to the last byte of the string, or None if it is empty.
Sourcepub fn last_mut(&mut self) -> Option<&mut u8>
pub fn last_mut(&mut self) -> Option<&mut u8>
Returns a mutable reference to the last byte of the string, or None if it is empty.
Sourcepub fn split_first(&self) -> Option<(&u8, &ByteStr)>
pub fn split_first(&self) -> Option<(&u8, &ByteStr)>
Returns the first and all the rest of the bytes of the slice, or None if it is empty.
Sourcepub fn split_first_mut(&mut self) -> Option<(&mut u8, &mut ByteStr)>
pub fn split_first_mut(&mut self) -> Option<(&mut u8, &mut ByteStr)>
Returns the first and all the rest of the bytes of the slice, or None if it is empty.
Sourcepub fn split_last(&self) -> Option<(&u8, &ByteStr)>
pub fn split_last(&self) -> Option<(&u8, &ByteStr)>
Returns the last and all the rest of the bytes of the slice, or None if it is empty.
Sourcepub fn split_last_mut(&mut self) -> Option<(&mut u8, &mut ByteStr)>
pub fn split_last_mut(&mut self) -> Option<(&mut u8, &mut ByteStr)>
Returns the last and all the rest of the bytes of the slice, or None if it is empty.
Sourcepub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, u8>
pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, u8>
Returns an iterator that allows modifying each value.
Sourcepub fn windows<'a>(&'a self, size: usize) -> Windows<'a> ⓘ
pub fn windows<'a>(&'a self, size: usize) -> Windows<'a> ⓘ
Returns an iterator over all contiguous windows of length size.
The windows overlap. If the string is shorter than size, the
iterator returns no values.
Similar to slice::windows().
Sourcepub fn chunks<'a>(&'a self, size: usize) -> Chunks<'a> ⓘ
pub fn chunks<'a>(&'a self, size: usize) -> Chunks<'a> ⓘ
Returns an iterator over size bytes of the string at a time. The chunks do not
overlap. If size does not divide the length of the slice, then the last chunk will
not have length size.
Similar to slice::chunks().
Sourcepub fn chunks_mut<'a>(&'a mut self, size: usize) -> ChunksMut<'a> ⓘ
pub fn chunks_mut<'a>(&'a mut self, size: usize) -> ChunksMut<'a> ⓘ
Returns an iterator over size elements of the slice at a time. The chunks are mutable
strings and do not overlap. If size does not divide the length of the slice, then the
last chunk will not have length size.
Similar to slice::chunks_mut().
Sourcepub fn split_at(&self, mid: usize) -> (&ByteStr, &ByteStr)
pub fn split_at(&self, mid: usize) -> (&ByteStr, &ByteStr)
Divides one string into two at an index.
The first will contain all indices from [0, mid) (excluding the index mid itself) and
the second will contain all indices from [mid, len) (excluding the index len itself).
Similar to slice::split_at().
§Panics
Panics if mid > len.
Sourcepub fn split_at_mut(&mut self, mid: usize) -> (&mut ByteStr, &mut ByteStr)
pub fn split_at_mut(&mut self, mid: usize) -> (&mut ByteStr, &mut ByteStr)
Divides one &mut string into two at an index.
The first will contain all indices from [0, mid) (excluding the index mid itself) and
the second will contain all indices from [mid, len) (excluding the index len itself).
Similar to slice::split_at_mut().
§Panics
Panics if mid > len.
Sourcepub fn split<'a, M: IntoMatcher>(&'a self, m: M) -> Split<'a, M::Matcher> ⓘ
pub fn split<'a, M: IntoMatcher>(&'a self, m: M) -> Split<'a, M::Matcher> ⓘ
Returns an iterator over substrings of this string, separated by a matcher.
Sourcepub fn split_mut<'a, M: IntoMatcher>(
&'a mut self,
m: M,
) -> SplitMut<'a, M::Matcher> ⓘ
pub fn split_mut<'a, M: IntoMatcher>( &'a mut self, m: M, ) -> SplitMut<'a, M::Matcher> ⓘ
Returns an iterator over mutable substrings of this string, separated by a matcher.
Sourcepub fn rsplit<'a, M: IntoMatcher>(&'a self, m: M) -> RSplit<'a, M::Matcher> ⓘ
pub fn rsplit<'a, M: IntoMatcher>(&'a self, m: M) -> RSplit<'a, M::Matcher> ⓘ
Returns an iterator over substrings of this string, separated by a matcher, starting at the end of the slice and working backwards.
Sourcepub fn rsplit_mut<'a, M: IntoMatcher>(
&'a mut self,
m: M,
) -> RSplitMut<'a, M::Matcher> ⓘ
pub fn rsplit_mut<'a, M: IntoMatcher>( &'a mut self, m: M, ) -> RSplitMut<'a, M::Matcher> ⓘ
Returns an iterator over mutable substrings of this string, separated by a matcher, starting at the end of the slice and working backwards.
Sourcepub fn splitn<'a, M: IntoMatcher>(
&'a self,
n: usize,
m: M,
) -> SplitN<'a, M::Matcher> ⓘ
pub fn splitn<'a, M: IntoMatcher>( &'a self, n: usize, m: M, ) -> SplitN<'a, M::Matcher> ⓘ
Returns an iterator over substrings of this string, separated by a matcher, returning
at most n items.
If n substrings are returned, the last substring will contain the remainder of the string.
Sourcepub fn splitn_mut<'a, M: IntoMatcher>(
&'a mut self,
n: usize,
m: M,
) -> SplitNMut<'a, M::Matcher> ⓘ
pub fn splitn_mut<'a, M: IntoMatcher>( &'a mut self, n: usize, m: M, ) -> SplitNMut<'a, M::Matcher> ⓘ
Returns an iterator over mutable substrings of this string, separated by a matcher, returning
at most n items.
If n substrings are returned, the last substring will contain the remainder of the string.
Sourcepub fn rsplitn<'a, M: IntoMatcher>(
&'a self,
n: usize,
m: M,
) -> RSplitN<'a, M::Matcher> ⓘ
pub fn rsplitn<'a, M: IntoMatcher>( &'a self, n: usize, m: M, ) -> RSplitN<'a, M::Matcher> ⓘ
Returns an iterator over substrings of this string, separated by a matcher and stating from
the end of the string, returning at most n items.
If n substrings are returned, the last substring will contain the remainder of the string.
Sourcepub fn rsplitn_mut<'a, M: IntoMatcher>(
&'a mut self,
n: usize,
m: M,
) -> RSplitNMut<'a, M::Matcher> ⓘ
pub fn rsplitn_mut<'a, M: IntoMatcher>( &'a mut self, n: usize, m: M, ) -> RSplitNMut<'a, M::Matcher> ⓘ
Returns an iterator over mutable substrings of this string, separated by a matcher and stating from
the end of the string, returning at most n items.
If n substrings are returned, the last substring will contain the remainder of the string.
Sourcepub fn matches<'a, M: IntoMatcher>(&'a self, m: M) -> Matches<'a, M::Matcher> ⓘ
pub fn matches<'a, M: IntoMatcher>(&'a self, m: M) -> Matches<'a, M::Matcher> ⓘ
Returns an iterator over the disjoint matches within the given string.
Sourcepub fn matches_mut<'a, M: IntoMatcher>(
&'a mut self,
m: M,
) -> MatchesMut<'a, M::Matcher> ⓘ
pub fn matches_mut<'a, M: IntoMatcher>( &'a mut self, m: M, ) -> MatchesMut<'a, M::Matcher> ⓘ
Returns an iterator over the mutable disjoint matches within the given string.
Sourcepub fn rmatches<'a, M: IntoMatcher>(&'a self, m: M) -> RMatches<'a, M::Matcher> ⓘ
pub fn rmatches<'a, M: IntoMatcher>(&'a self, m: M) -> RMatches<'a, M::Matcher> ⓘ
Returns an iterator over the disjoint matches within the given string, yielded in reverse order.
Sourcepub fn rmatches_mut<'a, M: IntoMatcher>(
&'a mut self,
m: M,
) -> RMatchesMut<'a, M::Matcher> ⓘ
pub fn rmatches_mut<'a, M: IntoMatcher>( &'a mut self, m: M, ) -> RMatchesMut<'a, M::Matcher> ⓘ
Returns an iterator over the mutable disjoint matches within the given string, yielded in reverse order.
Sourcepub fn match_indices<'a, M: IntoMatcher>(
&'a self,
m: M,
) -> MatchIndices<'a, M::Matcher> ⓘ
pub fn match_indices<'a, M: IntoMatcher>( &'a self, m: M, ) -> MatchIndices<'a, M::Matcher> ⓘ
Returns an iterator over the disjoint matches within the given string, as well as the index that the match starts at.
Sourcepub fn match_indices_mut<'a, M: IntoMatcher>(
&'a mut self,
m: M,
) -> MatchIndicesMut<'a, M::Matcher> ⓘ
pub fn match_indices_mut<'a, M: IntoMatcher>( &'a mut self, m: M, ) -> MatchIndicesMut<'a, M::Matcher> ⓘ
Returns an iterator over the mutable disjoint matches within the given string, as well as the index that the match starts at.
Sourcepub fn rmatch_indices<'a, M: IntoMatcher>(
&'a self,
m: M,
) -> RMatchIndices<'a, M::Matcher> ⓘ
pub fn rmatch_indices<'a, M: IntoMatcher>( &'a self, m: M, ) -> RMatchIndices<'a, M::Matcher> ⓘ
Returns an iterator over the disjoint matches within the given string, yielded in reverse order, as well as the index that the match starts at.
Sourcepub fn rmatch_indices_mut<'a, M: IntoMatcher>(
&'a mut self,
m: M,
) -> RMatchIndicesMut<'a, M::Matcher> ⓘ
pub fn rmatch_indices_mut<'a, M: IntoMatcher>( &'a mut self, m: M, ) -> RMatchIndicesMut<'a, M::Matcher> ⓘ
Returns an iterator over the mutable disjoint matches within the given string, yielded in reverse order, as well as the index that the match starts at.
Sourcepub fn contains<M: IntoMatcher>(&self, m: M) -> bool
pub fn contains<M: IntoMatcher>(&self, m: M) -> bool
Returns true if the string contains a substring that matches the given matcher.
Sourcepub fn starts_with<M: IntoMatcher>(&self, m: M) -> bool
pub fn starts_with<M: IntoMatcher>(&self, m: M) -> bool
Returns true if the string beginning a matches the given matcher.
Sourcepub fn ends_with<M: IntoMatcher>(&self, m: M) -> bool
pub fn ends_with<M: IntoMatcher>(&self, m: M) -> bool
Returns true if the string ending a matches the given matcher.
Sourcepub fn find<M: IntoMatcher>(&self, m: M) -> Option<usize>
pub fn find<M: IntoMatcher>(&self, m: M) -> Option<usize>
Returns the byte index of the first character of self that matches the
matcher or None it it doesn’t match.
Sourcepub fn rfind<M: IntoMatcher>(&self, m: M) -> Option<usize>
pub fn rfind<M: IntoMatcher>(&self, m: M) -> Option<usize>
Returns the byte index of the last character of self that matches the
matcher or None it it doesn’t match.
Sourcepub fn copy_from_slice(&mut self, src: &[u8])
pub fn copy_from_slice(&mut self, src: &[u8])
Copies all elements from src into self, using a memcpy.
The length of src must be the same as self.
Sourcepub fn copy_from_byte_str(&mut self, src: &ByteStr)
pub fn copy_from_byte_str(&mut self, src: &ByteStr)
Copies all elements from src into self, using a memcpy.
The length of src must be the same as self.