Skip to main content

SeqStr

Struct SeqStr 

Source
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

Source

pub fn new() -> Self

Create a new SeqStr

Source

pub fn is_empty(&self) -> bool

Check if the sequence is empty

Source

pub fn len(&self) -> usize

Get the number of str in the sequence

Source

pub fn reserve(&mut self, extra: usize)

Reserve capacity for more str’s

Source

pub fn shrink_to_fit(&mut self)

Shrink container to fit the current data

Source

pub fn get(&self, idx: usize) -> Option<&str>

Get the i’th element of the sequence in a checked manner

Source

pub fn get_mut(&mut self, idx: usize) -> Option<&mut str>

Get the i’th element of the sequence in a checked manner

Source

pub fn contains(&self, s: impl AsRef<str>) -> bool

Check if the sequence contains a particular string

Source

pub fn push(&mut self, s: impl AsRef<str>)

Push a &str onto the sequence

Source

pub fn last(&self) -> Option<&str>

Get the last str of the sequence

Source

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.

Source

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].

Source

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

Source

pub fn iter(&self) -> Map<SeqBytesIter<'_>, fn(&[u8]) -> &str>

Iterate over the sequence of &str

Source

pub fn iter_mut( &mut self, ) -> Map<SeqBytesIterMut<'_>, fn(&mut [u8]) -> &mut str>

Iterate over the sequence of &mut str

Source

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.

Source

pub fn truncate(&mut self, new_size: usize)

Truncate to at most the first n str

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn concat(&self) -> &str

Concatenate the str in the sequence into one string

Source

pub fn join(&self, separator: &str) -> String

Join the str in the sequence into one string, placing a separator between them

Trait Implementations§

Source§

impl Clone for SeqStr

Source§

fn clone(&self) -> SeqStr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SeqStr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SeqStr

Source§

fn default() -> SeqStr

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SeqStr

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for SeqStr

Source§

impl<A: AsRef<str>> Extend<A> for SeqStr

Source§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = A>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<A: AsRef<str>> FromIterator<A> for SeqStr

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = A>,

Creates a value from an iterator. Read more
Source§

impl Hash for SeqStr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<usize> for SeqStr

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &str

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for SeqStr

Source§

fn index_mut(&mut self, index: usize) -> &mut str

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a SeqStr

Source§

type Item = &'a str

The type of the elements being iterated over.
Source§

type IntoIter = Map<SeqBytesIter<'a>, fn(&[u8]) -> &str>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for SeqStr

Source§

fn eq(&self, other: &SeqStr) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SeqStr

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SeqStr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.