Struct lazy_concat::LazyConcat[][src]

pub struct LazyConcat<'a, T, B: ?Sized> where
    B: 'a + ToOwned
{ /* fields omitted */ }

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]

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.

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.

Fully normalize the collection by concatenating every fragament onto the base.

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.

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.

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);

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.

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);

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.

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.

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, using concat, 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]

Creates an iterator over the chars of the String and any concatenated fragments. No normalization needs to be done for this to work.

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]

Creates an iterator over references to items of a Vec and any concatenated fragments. No normalization needs to be done for this to work.

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]

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]

Performs the conversion.

Auto Trait Implementations

impl<'a, T, B: ?Sized> Send for LazyConcat<'a, T, B> where
    B: Sync,
    T: Send,
    <B as ToOwned>::Owned: Send

impl<'a, T, B: ?Sized> Sync for LazyConcat<'a, T, B> where
    B: Sync,
    T: Sync,
    <B as ToOwned>::Owned: Sync