pub struct SeqStr { /* private fields */ }Expand description
A sequence of &str, stored contiguously
This can be used as a drop-in replacement for Vec<String> in some cases,
with better memory locality and fewer memory allocations.
When using SeqBytes instead of Vec<String>, the individual strings
cannot be resized, but when this isn’t needed there isn’t much downside otherwise.
The container also supports “emplace”-style APIs like in_place_writer, which allow you to
write the next element directly into the contiguous buffer with minimal overhead.
SeqStr::from_display_iter allows you to collect an iterator of impl Display items,
formatting them directly into the contiguous buffer.
Implementations§
Source§impl SeqStr
impl SeqStr
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink container to fit the current data
Sourcepub fn get(&self, idx: usize) -> Option<&str>
pub fn get(&self, idx: usize) -> Option<&str>
Get the i’th element of the sequence in a checked manner
Sourcepub fn get_mut(&mut self, idx: usize) -> Option<&mut str>
pub fn get_mut(&mut self, idx: usize) -> Option<&mut str>
Get the i’th element of the sequence in a checked manner
Sourcepub fn contains(&self, s: impl AsRef<str>) -> bool
pub fn contains(&self, s: impl AsRef<str>) -> bool
Check if the sequence contains a particular string
Sourcepub fn pop(&mut self)
pub fn pop(&mut self)
Pop the last element of the container Note that we can’t return it because of lifetimes, so call [last] before popping.
Sourcepub fn range(
&self,
range_bounds: impl RangeBounds<usize>,
) -> Map<SeqBytesIter<'_>, fn(&[u8]) -> &str>
pub fn range( &self, range_bounds: impl RangeBounds<usize>, ) -> Map<SeqBytesIter<'_>, fn(&[u8]) -> &str>
Iterate over a range of the sequence of &str
This resembles std::collections::BTreeMap::range, and is needed becuase like BTreeMap,
we can’t implement Deref or SliceIndex<Range> and produce a slice of our contents.
See also [as_vec].
Sourcepub fn range_mut(
&mut self,
range_bounds: impl RangeBounds<usize>,
) -> Map<SeqBytesIterMut<'_>, fn(&mut [u8]) -> &mut str>
pub fn range_mut( &mut self, range_bounds: impl RangeBounds<usize>, ) -> Map<SeqBytesIterMut<'_>, fn(&mut [u8]) -> &mut str>
Iterate over a range of the sequence of &mut u8
Sourcepub fn iter(&self) -> Map<SeqBytesIter<'_>, fn(&[u8]) -> &str>
pub fn iter(&self) -> Map<SeqBytesIter<'_>, fn(&[u8]) -> &str>
Iterate over the sequence of &str
Sourcepub fn iter_mut(
&mut self,
) -> Map<SeqBytesIterMut<'_>, fn(&mut [u8]) -> &mut str>
pub fn iter_mut( &mut self, ) -> Map<SeqBytesIterMut<'_>, fn(&mut [u8]) -> &mut str>
Iterate over the sequence of &mut str
Sourcepub fn chunks(
&self,
chunk_size: usize,
) -> impl Clone + ExactSizeIterator<Item = impl Clone + ExactSizeIterator<Item = &str>>
pub fn chunks( &self, chunk_size: usize, ) -> impl Clone + ExactSizeIterator<Item = impl Clone + ExactSizeIterator<Item = &str>>
Iterate over the sequence of &str, in chunks of given size.
Returns an iterator which yields one iterator for each chunk, each of which
yields chunk_size string values.
The last chunk may be smaller.
Sourcepub fn resize(&mut self, new_size: usize)
pub fn resize(&mut self, new_size: usize)
Resize to contain only the first n str, or pad up to n str, with empty str added
Sourcepub fn retain(&mut self, pred: impl FnMut(&str) -> bool)
pub fn retain(&mut self, pred: impl FnMut(&str) -> bool)
Retain only those str satisfying a predicate.
The str are always visited in order, similar to std::vec::Vec::retain.
Sourcepub fn retain_mut(&mut self, pred: impl FnMut(&mut str) -> bool)
pub fn retain_mut(&mut self, pred: impl FnMut(&mut str) -> bool)
Retain only those str satisfying a predicate.
The str are always visited in order, similar to std::vec::Vec::retain_mut.
Sourcepub fn in_place_writer(&mut self) -> impl Write
pub fn in_place_writer(&mut self) -> impl Write
Get an impl std::fmt::Write which can be used to write the next slice
directly into the buffer without copying.
Sourcepub fn from_display_iter<T: Display, I: Iterator<Item = T>>(it: I) -> Self
pub fn from_display_iter<T: Display, I: Iterator<Item = T>>(it: I) -> Self
Construct SeqStr from any items that implement Display,
formatting them directly into the contiguous buffer.
Sourcepub fn as_vec(&self) -> Vec<&str>
pub fn as_vec(&self) -> Vec<&str>
Express as a Vec<&str>. The main reason that this may be useful is that there are
useful methods on slice types &[&str], for example, [core::slice::binary_search],
but SeqStr itself doesn’t implement Deref the way that Vec does and can
only produce such a slice by allocating.
See SeqBytes::as_vec for more discussion of tradeoffs.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SeqStr
impl<'de> Deserialize<'de> for SeqStr
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for SeqStr
Source§impl<A: AsRef<str>> Extend<A> for SeqStr
impl<A: AsRef<str>> Extend<A> for SeqStr
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = A>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = A>,
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)