Struct lazy_concat::LazyConcat [−][src]
Methods
impl<'a, T, B: ?Sized> LazyConcat<'a, T, B> where
T: Concat<Cow<'a, B>> + Borrow<B> + Default + Length,
B: ToOwned<Owned = T> + Length,
[src]
impl<'a, T, B: ?Sized> LazyConcat<'a, T, B> where
T: Concat<Cow<'a, B>> + Borrow<B> + Default + Length,
B: ToOwned<Owned = T> + Length,
pub fn new(initial: T) -> Self
[src]
pub fn new(initial: T) -> Self
Construct a new LazyConcat
. The initial value should be an owned value, such as a Vec
or
a String
. This can be empty but it doesn't have to be.
pub fn expecting_num_fragments(initial: T, n: usize) -> Self
[src]
pub fn expecting_num_fragments(initial: T, n: usize) -> Self
Construct a new LazyConcat
, but preallocate the vector of fragments with the expected number
of fragments, so that won't need to be reallocated as fragments are added.
pub fn normalize(&mut self)
[src]
pub fn normalize(&mut self)
Fully normalize the collection by concatenating every fragament onto the base.
pub fn normalize_to_len(&mut self, len: usize) -> Option<usize>
[src]
pub fn normalize_to_len(&mut self, len: usize) -> Option<usize>
Normalize at least len
elements and return the number of elements that were actually normalized.
This could fail if there are not enough fragments to make up the required length, in which case
None
is returned and no work is done.
pub fn get_normalized_len(&self) -> usize
[src]
pub fn get_normalized_len(&self) -> usize
The amount of data (in bytes) that has already been normalized. This is the maximum length
of a slice that can be taken without first calling normalize
or
normalize_to_len
.
pub fn slice_needs_normalization<R: RangeBounds<usize>>(
&mut self,
range: R
) -> bool
[src]
pub fn slice_needs_normalization<R: RangeBounds<usize>>(
&mut self,
range: R
) -> bool
Checks if any normalization is required before taking a slice
Examples
if lz.slice_needs_normalization(1..3) { lz.normalize_to_len(4); } let slice = lz.get_slice(1..3);
pub fn get_slice<R>(&self, range: R) -> &B where
R: RangeBounds<usize>,
T: Sliceable<Slice = B>,
[src]
pub fn get_slice<R>(&self, range: R) -> &B where
R: RangeBounds<usize>,
T: Sliceable<Slice = B>,
Get a slice from the normalized data. Before calling this method you should check that the size of
the normalized data is sufficient to be able to support this slice and, if necessary normalizing
the data to the required size using normalize_to_len
.
Panics
Panics when the range falls outside the size of the owned data.
pub fn done(self) -> T
[src]
pub fn done(self) -> T
Consume the LazyConcat, concatenate all of the fragments and return the owned, fully normalized data.
Examples
let lz = LazyConcat::new(String::from("abc")) .and_concat("def") .and_concat("ghi"); let result: String = lz.done(); assert_eq!("abcdefghi", result);
pub fn and_concat<F: Into<Cow<'a, B>>>(self, fragment: F) -> Self
[src]
pub fn and_concat<F: Into<Cow<'a, B>>>(self, fragment: F) -> Self
Lazily concatenate an owned or borrowed fragment of data. No data will be moved or copied until the
next time that normalize
or normalize_to_len
is called.
This is the same as [concat
] except that it consumes and returns self, allowing for
method chaining.
pub fn concat<F: Into<Cow<'a, B>>>(&mut self, fragment: F)
[src]
pub fn concat<F: Into<Cow<'a, B>>>(&mut self, fragment: F)
Lazily concatenate an owned or borrowed fragment of data. No data will be moved or copied until the
next time that normalize
or normalize_to_len
is called.
pub fn split_normalized<'b>(
&'b mut self
) -> (&'b B, ConcatOnly<&'b mut LazyConcat<'a, T, B>>) where
T: Sliceable<Slice = B>,
[src]
pub fn split_normalized<'b>(
&'b mut self
) -> (&'b B, ConcatOnly<&'b mut LazyConcat<'a, T, B>>) where
T: Sliceable<Slice = B>,
Splits the LazyConcat
into two parts:
- An immutable borrow of the normalized concatenation of the root.
- A mutable view,
ConcatOnly
, which permits further lazy concatenation, usingconcat
, but no other mutation.
This lets you keep hold of a slice into the normalized root, while still allowing further concatenation
of fragments. This would not otherwise be possible because and_concat
consumes
self
and concat
takes &mut self
, preventing slices into
the normalized root to exist.
Examples
let a = vec![0,1,2,3,4]; let mut lz = LazyConcat::new(Vec::new()) .and_concat(&a); lz.normalize(); // New block scope to control the lifespan of the variables { let (norm, mut lz) = lz.split_normalized(); let slice = &norm[0..]; // Still possible to concatenate while holding a slice lz.concat(vec![99]); assert_eq!(vec![0,1,2,3,4], slice); } assert_eq!(vec![0,1,2,3,4,99], lz.done());
impl<'a> LazyConcat<'a, String, str>
[src]
impl<'a> LazyConcat<'a, String, str>
pub fn chars<'b>(
&'b self
) -> impl Iterator<Item = char> + 'b
[src]
pub fn chars<'b>(
&'b self
) -> impl Iterator<Item = char> + 'b
Creates an iterator over the char
s of the String and any concatenated fragments.
No normalization needs to be done for this to work.
pub fn bytes<'b>(
&'b self
) -> impl Iterator<Item = u8> + 'b
[src]
pub fn bytes<'b>(
&'b self
) -> impl Iterator<Item = u8> + 'b
Creates an iterator over the raw bytes of the String and any concatenated fragments. No normalization needs to be done for this to work.
impl<'a, I: Clone> LazyConcat<'a, Vec<I>, [I]>
[src]
impl<'a, I: Clone> LazyConcat<'a, Vec<I>, [I]>
pub fn iter(
&self
) -> impl Iterator<Item = &I>
[src]
pub fn iter(
&self
) -> impl Iterator<Item = &I>
Creates an iterator over references to items of a Vec and any concatenated fragments. No normalization needs to be done for this to work.
pub fn into_iter<'b>(
&'b self
) -> impl Iterator<Item = I> + 'b
[src]
pub fn into_iter<'b>(
&'b self
) -> impl Iterator<Item = I> + 'b
Creates an iterator over the owned items of a Vec and any concatenated fragments. No normalization needs to be done for this to work.
Trait Implementations
impl<'a, T, B: ?Sized> Debug for LazyConcat<'a, T, B> where
T: Concat<Cow<'a, B>> + Borrow<B> + Debug,
B: ToOwned<Owned = T> + Debug,
[src]
impl<'a, T, B: ?Sized> Debug for LazyConcat<'a, T, B> where
T: Concat<Cow<'a, B>> + Borrow<B> + Debug,
B: ToOwned<Owned = T> + Debug,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a, T, B: ?Sized> From<T> for LazyConcat<'a, T, B> where
T: Concat<Cow<'a, B>> + Borrow<B> + Default + Length,
B: ToOwned<Owned = T> + Length,
[src]
impl<'a, T, B: ?Sized> From<T> for LazyConcat<'a, T, B> where
T: Concat<Cow<'a, B>> + Borrow<B> + Default + Length,
B: ToOwned<Owned = T> + Length,