1.0.0[][src]Trait prcn_lib::prelude::__std_iter::Extend

pub trait Extend<A> {
    fn extend<T>(&mut self, iter: T)
    where
        T: IntoIterator<Item = A>
; }

Extend a collection with the contents of an iterator.

Iterators produce a series of values, and collections can also be thought of as a series of values. The Extend trait bridges this gap, allowing you to extend a collection by including the contents of that iterator. When extending a collection with an already existing key, that entry is updated or, in the case of collections that permit multiple entries with equal keys, that entry is inserted.

Examples

Basic usage:

// You can extend a String with some chars:
let mut message = String::from("The first three letters are: ");

message.extend(&['a', 'b', 'c']);

assert_eq!("abc", &message[29..32]);

Implementing Extend:

// A sample collection, that's just a wrapper over Vec<T>
#[derive(Debug)]
struct MyCollection(Vec<i32>);

// Let's give it some methods so we can create one and add things
// to it.
impl MyCollection {
    fn new() -> MyCollection {
        MyCollection(Vec::new())
    }

    fn add(&mut self, elem: i32) {
        self.0.push(elem);
    }
}

// since MyCollection has a list of i32s, we implement Extend for i32
impl Extend<i32> for MyCollection {

    // This is a bit simpler with the concrete type signature: we can call
    // extend on anything which can be turned into an Iterator which gives
    // us i32s. Because we need i32s to put into MyCollection.
    fn extend<T: IntoIterator<Item=i32>>(&mut self, iter: T) {

        // The implementation is very straightforward: loop through the
        // iterator, and add() each element to ourselves.
        for elem in iter {
            self.add(elem);
        }
    }
}

let mut c = MyCollection::new();

c.add(5);
c.add(6);
c.add(7);

// let's extend our collection with three more numbers
c.extend(vec![1, 2, 3]);

// we've added these elements onto the end
assert_eq!("MyCollection([5, 6, 7, 1, 2, 3])", format!("{:?}", c));

Required methods

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

Extends a collection with the contents of an iterator.

As this is the only method for this trait, the trait-level docs contain more details.

Examples

Basic usage:

// You can extend a String with some chars:
let mut message = String::from("abc");

message.extend(['d', 'e', 'f'].iter());

assert_eq!("abcdef", &message);
Loading content...

Implementations on Foreign Types

impl<P> Extend<P> for PathBuf where
    P: AsRef<Path>, 
[src]

impl Extend<()> for ()[src]

impl<'a> Extend<&'a char> for String[src]

impl<'a> Extend<&'a str> for String[src]

impl<'a, T> Extend<&'a T> for LinkedList<T> where
    T: 'a + Copy
[src]

impl<T> Extend<T> for BinaryHeap<T> where
    T: Ord
[src]

impl Extend<String> for String[src]

impl<'a> Extend<Cow<'a, str>> for String[src]

impl<T> Extend<T> for LinkedList<T>[src]

impl<'a, T> Extend<&'a T> for BinaryHeap<T> where
    T: 'a + Ord + Copy
[src]

impl Extend<char> for String[src]

impl<'a, T> Extend<&'a T> for Vec<T> where
    T: 'a + Copy
[src]

Extend implementation that copies elements out of references before pushing them onto the Vec.

This implementation is specialized for slice iterators, where it uses copy_from_slice to append the entire slice at once.

impl<T> Extend<T> for Vec<T>[src]

impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S> where
    K: Eq + Hash + Copy,
    S: BuildHasher,
    V: Copy

impl<T, S> Extend<T> for HashSet<T, S> where
    S: BuildHasher,
    T: Eq + Hash

impl<'a, T, S> Extend<&'a T> for HashSet<T, S> where
    S: BuildHasher,
    T: 'a + Eq + Hash + Copy

impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher

impl<A> Extend<A> for AsciiString where
    A: AsRef<AsciiStr>, 
[src]

impl Extend<usize> for FixedBitSet[src]

Sets the bit at index i to true for each item i in the input src.

impl<A, R> Extend<R> for OrdSet<A> where
    A: Ord + Clone + From<R>, 
[src]

impl<A> Extend<A> for Vector<A> where
    A: Clone
[src]

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = A>, 
[src]

Add values to the end of a vector by consuming an iterator.

Time: O(n)

impl<A, S, R> Extend<R> for HashSet<A, S> where
    A: Hash + Eq + Clone + From<R>,
    S: BuildHasher
[src]

impl<K, V, S, RK, RV> Extend<(RK, RV)> for HashMap<K, V, S> where
    K: Hash + Eq + Clone + From<RK>,
    S: BuildHasher,
    V: Clone + From<RV>, 
[src]

impl<K, V, RK, RV> Extend<(RK, RV)> for OrdMap<K, V> where
    K: Ord + Clone + From<RK>,
    V: Clone + From<RV>, 
[src]

impl<'a, A, N> Extend<&'a A> for RingBuffer<A, N> where
    A: 'a + Clone,
    N: ChunkLength<A>, 

impl<A, T> Extend<A> for InlineArray<A, T>

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

Append the contents of the iterator to the back of the array.

Panics if the array exceeds its capacity.

Time: O(n) for the length of the iterator

impl<'a, A, T> Extend<&'a A> for InlineArray<A, T> where
    A: 'a + Copy

fn extend<I>(&mut self, it: I) where
    I: IntoIterator<Item = &'a A>, 

Append the contents of the iterator to the back of the array.

Panics if the array exceeds its capacity.

Time: O(n) for the length of the iterator

impl<A, N> Extend<A> for RingBuffer<A, N> where
    N: ChunkLength<A>, 

impl<A, N> Extend<A> for Chunk<A, N> where
    N: ChunkLength<A>, 

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

Append the contents of the iterator to the back of the chunk.

Panics if the chunk exceeds its capacity.

Time: O(n) for the length of the iterator

impl<'a, A, N> Extend<&'a A> for Chunk<A, N> where
    A: 'a + Copy,
    N: ChunkLength<A>, 

fn extend<I>(&mut self, it: I) where
    I: IntoIterator<Item = &'a A>, 

Append the contents of the iterator to the back of the chunk.

Panics if the chunk exceeds its capacity.

Time: O(n) for the length of the iterator

impl<'a, K, V, S> Extend<(&'a K, &'a V)> for IndexMap<K, V, S> where
    K: Hash + Eq + Copy,
    S: BuildHasher,
    V: Copy
[src]

fn extend<I>(&mut self, iterable: I) where
    I: IntoIterator<Item = (&'a K, &'a V)>, 
[src]

Extend the map with all key-value pairs in the iterable.

See the first extend method for more details.

impl<'a, T, S> Extend<&'a T> for IndexSet<T, S> where
    S: BuildHasher,
    T: Hash + Eq + Copy + 'a, 
[src]

impl<T, S> Extend<T> for IndexSet<T, S> where
    S: BuildHasher,
    T: Hash + Eq
[src]

impl<K, V, S> Extend<(K, V)> for IndexMap<K, V, S> where
    K: Hash + Eq,
    S: BuildHasher
[src]

fn extend<I>(&mut self, iterable: I) where
    I: IntoIterator<Item = (K, V)>, 
[src]

Extend the map with all key-value pairs in the iterable.

This is equivalent to calling insert for each of them in order, which means that for keys that already existed in the map, their value is updated but it keeps the existing order.

New keys are inserted in the order they appear in the sequence. If equivalents of a key occur more than once, the last corresponding value prevails.

impl<N> Extend<N> for VecStorage<N, Dynamic, U1>[src]

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = N>, 
[src]

Extends the number of rows of the VecStorage with elements from the given iterator.

impl<'a, N, R> Extend<&'a N> for VecStorage<N, R, Dynamic> where
    N: 'a + Copy,
    R: Dim
[src]

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = &'a N>, 
[src]

Extends the number of columns of the VecStorage with elements from the given iterator.

Panics

This function panics if the number of elements yielded by the given iterator is not a multiple of the number of rows of the VecStorage.

impl<N, R, S> Extend<N> for Matrix<N, R, Dynamic, S> where
    N: Scalar,
    R: Dim,
    S: Extend<N>, 
[src]

Extend the number of columns of the Matrix with elements from a given iterator.

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = N>, 
[src]

Extend the number of columns of the Matrix with elements from the given iterator.

Example


let data = vec![0, 1, 2,      // column 1
                3, 4, 5];     // column 2

let mut matrix = DMatrix::from_vec(3, 2, data);

matrix.extend(vec![6, 7, 8]); // column 3

assert!(matrix.eq(&Matrix3::new(0, 3, 6,
                                1, 4, 7,
                                2, 5, 8)));

Panics

This function panics if the number of elements yielded by the given iterator is not a multiple of the number of rows of the Matrix.

let data = vec![0, 1, 2,  // column 1
                3, 4, 5]; // column 2

let mut matrix = DMatrix::from_vec(3, 2, data);

// The following panics because the vec length is not a multiple of 3.
matrix.extend(vec![6, 7, 8, 9]);

impl<N, S> Extend<N> for Matrix<N, Dynamic, U1, S> where
    N: Scalar,
    S: Extend<N>, 
[src]

Extend the number of rows of the Vector with elements from a given iterator.

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = N>, 
[src]

Extend the number of rows of a Vector with elements from the given iterator.

Example

let mut vector = DVector::from_vec(vec![0, 1, 2]);
vector.extend(vec![3, 4, 5]);
assert!(vector.eq(&DVector::from_vec(vec![0, 1, 2, 3, 4, 5])));

impl<N, R, S, RV, SV> Extend<Matrix<N, RV, U1, SV>> for Matrix<N, R, Dynamic, S> where
    N: Scalar,
    R: Dim,
    RV: Dim,
    S: Extend<Matrix<N, RV, U1, SV>>,
    SV: Storage<N, RV, U1>,
    ShapeConstraint: SameNumberOfRows<R, RV>, 
[src]

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = Matrix<N, RV, U1, SV>>, 
[src]

Extends the number of columns of a Matrix with Vectors from a given iterator.

Example


let data = vec![0, 1, 2,          // column 1
                3, 4, 5];         // column 2

let mut matrix = DMatrix::from_vec(3, 2, data);

matrix.extend(
  vec![Vector3::new(6,  7,  8),   // column 3
       Vector3::new(9, 10, 11)]); // column 4

assert!(matrix.eq(&Matrix3x4::new(0, 3, 6,  9,
                                  1, 4, 7, 10,
                                  2, 5, 8, 11)));

Panics

This function panics if the dimension of each Vector yielded by the given iterator is not equal to the number of rows of this Matrix.

let mut matrix =
  DMatrix::from_vec(3, 2,
                    vec![0, 1, 2,   // column 1
                         3, 4, 5]); // column 2

// The following panics because this matrix can only be extended with 3-dimensional vectors.
matrix.extend(
  vec![Vector2::new(6,  7)]); // too few dimensions!
let mut matrix =
  DMatrix::from_vec(3, 2,
                    vec![0, 1, 2,   // column 1
                         3, 4, 5]); // column 2

// The following panics because this matrix can only be extended with 3-dimensional vectors.
matrix.extend(
  vec![Vector4::new(6, 7, 8, 9)]); // too few dimensions!

impl<N, R, RV, SV> Extend<Matrix<N, RV, U1, SV>> for VecStorage<N, R, Dynamic> where
    N: Scalar,
    R: Dim,
    RV: Dim,
    SV: Storage<N, RV, U1>,
    ShapeConstraint: SameNumberOfRows<R, RV>, 
[src]

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = Matrix<N, RV, U1, SV>>, 
[src]

Extends the number of columns of the VecStorage with vectors from the given iterator.

Panics

This function panics if the number of rows of each Vector yielded by the iterator is not equal to the number of rows of this VecStorage.

impl<N, R> Extend<N> for VecStorage<N, R, Dynamic> where
    R: Dim
[src]

fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = N>, 
[src]

Extends the number of columns of the VecStorage with elements from the given iterator.

Panics

This function panics if the number of elements yielded by the given iterator is not a multiple of the number of rows of the VecStorage.

impl<N, E, Ty, Item> Extend<Item> for GraphMap<N, E, Ty> where
    Item: IntoWeightedEdge<E, NodeId = N>,
    N: NodeTrait,
    Ty: EdgeType
[src]

Extend the graph from an iterable of edges.

Nodes are inserted automatically to match the edges.

impl<A> Extend<<A as Array>::Item> for SmallVec<A> where
    A: Array
[src]

Loading content...

Implementors

impl<'a, K, V> Extend<(&'a K, &'a V)> for BTreeMap<K, V> where
    K: Ord + Copy,
    V: Copy
[src]

impl<'a, K, V, S> Extend<(&'a K, &'a V)> for prcn_lib::prelude::HashMap<K, V, S> where
    K: Eq + Hash + Copy,
    S: BuildHasher,
    V: Copy
[src]

impl<'a, T> Extend<&'a T> for BTreeSet<T> where
    T: 'a + Ord + Copy
[src]

impl<'a, T> Extend<&'a T> for VecDeque<T> where
    T: 'a + Copy
[src]

impl<'a, T, S> Extend<&'a T> for prcn_lib::prelude::HashSet<T, S> where
    S: BuildHasher,
    T: 'a + Eq + Hash + Copy
[src]

impl<A> Extend<A> for VecDeque<A>[src]

impl<K, V> Extend<(K, V)> for BTreeMap<K, V> where
    K: Ord
[src]

impl<K, V, S> Extend<(K, V)> for prcn_lib::prelude::HashMap<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

Inserts all new key-values from the iterator and replaces values with existing keys with new values returned from the iterator.

impl<L, R, A> Extend<A> for Either<L, R> where
    L: Extend<A>,
    R: Extend<A>, 
[src]

impl<T> Extend<T> for BTreeSet<T> where
    T: Ord
[src]

impl<T, S> Extend<T> for prcn_lib::prelude::HashSet<T, S> where
    S: BuildHasher,
    T: Eq + Hash
[src]

Loading content...