1.0.0[−][src]Trait prcn_lib::prelude::__std_iter::Extend
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>,
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);
Implementations on Foreign Types
impl<P> Extend<P> for PathBuf where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = P>,
[src]
I: IntoIterator<Item = P>,
impl Extend<()> for ()
[src]
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = ()>,
[src]
T: IntoIterator<Item = ()>,
impl<'a> Extend<&'a char> for String
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a char>,
[src]
I: IntoIterator<Item = &'a char>,
impl<'a> Extend<&'a str> for String
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a str>,
[src]
I: IntoIterator<Item = &'a str>,
impl<'a, T> Extend<&'a T> for LinkedList<T> where
T: 'a + Copy,
[src]
T: 'a + Copy,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
[src]
I: IntoIterator<Item = &'a T>,
impl<T> Extend<T> for BinaryHeap<T> where
T: Ord,
[src]
T: Ord,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl Extend<String> for String
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = String>,
[src]
I: IntoIterator<Item = String>,
impl<'a> Extend<Cow<'a, str>> for String
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = Cow<'a, str>>,
[src]
I: IntoIterator<Item = Cow<'a, str>>,
impl<T> Extend<T> for LinkedList<T>
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<'a, T> Extend<&'a T> for BinaryHeap<T> where
T: 'a + Ord + Copy,
[src]
T: 'a + Ord + Copy,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
[src]
I: IntoIterator<Item = &'a T>,
impl Extend<char> for String
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = char>,
[src]
I: IntoIterator<Item = char>,
impl<'a, T> Extend<&'a T> for Vec<T> where
T: 'a + Copy,
[src]
T: 'a + Copy,
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.
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
[src]
I: IntoIterator<Item = &'a T>,
impl<T> Extend<T> for Vec<T>
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S> where
K: Eq + Hash + Copy,
S: BuildHasher,
V: Copy,
K: Eq + Hash + Copy,
S: BuildHasher,
V: Copy,
impl<T, S> Extend<T> for HashSet<T, S> where
S: BuildHasher,
T: Eq + Hash,
S: BuildHasher,
T: Eq + Hash,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
I: IntoIterator<Item = T>,
impl<'a, T, S> Extend<&'a T> for HashSet<T, S> where
S: BuildHasher,
T: 'a + Eq + Hash + Copy,
S: BuildHasher,
T: 'a + Eq + Hash + Copy,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
I: IntoIterator<Item = &'a T>,
impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
K: Eq + Hash,
S: BuildHasher,
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (K, V)>,
T: IntoIterator<Item = (K, V)>,
impl<A> Extend<A> for AsciiString where
A: AsRef<AsciiStr>,
[src]
A: AsRef<AsciiStr>,
fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = A>,
[src]
I: IntoIterator<Item = A>,
impl Extend<usize> for FixedBitSet
[src]
Sets the bit at index i to true for each item i in the input src.
fn extend<I>(&mut self, src: I) where
I: IntoIterator<Item = usize>,
[src]
I: IntoIterator<Item = usize>,
impl<A, R> Extend<R> for OrdSet<A> where
A: Ord + Clone + From<R>,
[src]
A: Ord + Clone + From<R>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = R>,
[src]
I: IntoIterator<Item = R>,
impl<A> Extend<A> for Vector<A> where
A: Clone,
[src]
A: Clone,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = A>,
[src]
I: IntoIterator<Item = A>,
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]
A: Hash + Eq + Clone + From<R>,
S: BuildHasher,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = R>,
[src]
I: IntoIterator<Item = R>,
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]
K: Hash + Eq + Clone + From<RK>,
S: BuildHasher,
V: Clone + From<RV>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (RK, RV)>,
[src]
I: IntoIterator<Item = (RK, RV)>,
impl<K, V, RK, RV> Extend<(RK, RV)> for OrdMap<K, V> where
K: Ord + Clone + From<RK>,
V: Clone + From<RV>,
[src]
K: Ord + Clone + From<RK>,
V: Clone + From<RV>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (RK, RV)>,
[src]
I: IntoIterator<Item = (RK, RV)>,
impl<'a, A, N> Extend<&'a A> for RingBuffer<A, N> where
A: 'a + Clone,
N: ChunkLength<A>,
A: 'a + Clone,
N: ChunkLength<A>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a A>,
I: IntoIterator<Item = &'a A>,
impl<A, T> Extend<A> for InlineArray<A, T>
fn extend<I>(&mut self, it: I) where
I: IntoIterator<Item = A>,
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,
A: 'a + Copy,
fn extend<I>(&mut self, it: I) where
I: IntoIterator<Item = &'a A>,
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>,
N: ChunkLength<A>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = A>,
I: IntoIterator<Item = A>,
impl<A, N> Extend<A> for Chunk<A, N> where
N: ChunkLength<A>,
N: ChunkLength<A>,
fn extend<I>(&mut self, it: I) where
I: IntoIterator<Item = A>,
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>,
A: 'a + Copy,
N: ChunkLength<A>,
fn extend<I>(&mut self, it: I) where
I: IntoIterator<Item = &'a A>,
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]
K: Hash + Eq + Copy,
S: BuildHasher,
V: Copy,
fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = (&'a K, &'a V)>,
[src]
I: IntoIterator<Item = (&'a K, &'a V)>,
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]
S: BuildHasher,
T: Hash + Eq + Copy + 'a,
fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = &'a T>,
[src]
I: IntoIterator<Item = &'a T>,
impl<T, S> Extend<T> for IndexSet<T, S> where
S: BuildHasher,
T: Hash + Eq,
[src]
S: BuildHasher,
T: Hash + Eq,
fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<K, V, S> Extend<(K, V)> for IndexMap<K, V, S> where
K: Hash + Eq,
S: BuildHasher,
[src]
K: Hash + Eq,
S: BuildHasher,
fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
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]
I: IntoIterator<Item = N>,
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]
N: 'a + Copy,
R: Dim,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a N>,
[src]
I: IntoIterator<Item = &'a N>,
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]
N: Scalar,
R: Dim,
S: Extend<N>,
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]
I: IntoIterator<Item = N>,
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]
N: Scalar,
S: Extend<N>,
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]
I: IntoIterator<Item = N>,
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]
N: Scalar,
R: Dim,
RV: Dim,
S: Extend<Matrix<N, RV, U1, SV>>,
SV: Storage<N, RV, U1>,
ShapeConstraint: SameNumberOfRows<R, RV>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = Matrix<N, RV, U1, SV>>,
[src]
I: IntoIterator<Item = Matrix<N, RV, U1, SV>>,
Extends the number of columns of a Matrix
with Vector
s
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]
N: Scalar,
R: Dim,
RV: Dim,
SV: Storage<N, RV, U1>,
ShapeConstraint: SameNumberOfRows<R, RV>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = Matrix<N, RV, U1, SV>>,
[src]
I: IntoIterator<Item = Matrix<N, RV, U1, SV>>,
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]
R: Dim,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = N>,
[src]
I: IntoIterator<Item = N>,
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]
Item: IntoWeightedEdge<E, NodeId = N>,
N: NodeTrait,
Ty: EdgeType,
Extend the graph from an iterable of edges.
Nodes are inserted automatically to match the edges.
fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = Item>,
[src]
I: IntoIterator<Item = Item>,
impl<A> Extend<<A as Array>::Item> for SmallVec<A> where
A: Array,
[src]
A: Array,
fn extend<I>(&mut self, iterable: I) where
I: IntoIterator<Item = <A as Array>::Item>,
[src]
I: IntoIterator<Item = <A as Array>::Item>,
Implementors
impl<'a, K, V> Extend<(&'a K, &'a V)> for BTreeMap<K, V> where
K: Ord + Copy,
V: Copy,
[src]
K: Ord + Copy,
V: Copy,
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]
K: Eq + Hash + Copy,
S: BuildHasher,
V: Copy,
impl<'a, T> Extend<&'a T> for BTreeSet<T> where
T: 'a + Ord + Copy,
[src]
T: 'a + Ord + Copy,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
[src]
I: IntoIterator<Item = &'a T>,
impl<'a, T> Extend<&'a T> for VecDeque<T> where
T: 'a + Copy,
[src]
T: 'a + Copy,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
[src]
I: IntoIterator<Item = &'a T>,
impl<'a, T, S> Extend<&'a T> for prcn_lib::prelude::HashSet<T, S> where
S: BuildHasher,
T: 'a + Eq + Hash + Copy,
[src]
S: BuildHasher,
T: 'a + Eq + Hash + Copy,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = &'a T>,
[src]
I: IntoIterator<Item = &'a T>,
impl<A> Extend<A> for VecDeque<A>
[src]
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = A>,
[src]
T: IntoIterator<Item = A>,
impl<K, V> Extend<(K, V)> for BTreeMap<K, V> where
K: Ord,
[src]
K: Ord,
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (K, V)>,
[src]
T: IntoIterator<Item = (K, V)>,
impl<K, V, S> Extend<(K, V)> for prcn_lib::prelude::HashMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
Inserts all new key-values from the iterator and replaces values with existing keys with new values returned from the iterator.
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (K, V)>,
[src]
T: IntoIterator<Item = (K, V)>,
impl<L, R, A> Extend<A> for Either<L, R> where
L: Extend<A>,
R: Extend<A>,
[src]
L: Extend<A>,
R: Extend<A>,
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = A>,
[src]
T: IntoIterator<Item = A>,
impl<T> Extend<T> for BTreeSet<T> where
T: Ord,
[src]
T: Ord,
fn extend<Iter>(&mut self, iter: Iter) where
Iter: IntoIterator<Item = T>,
[src]
Iter: IntoIterator<Item = T>,
impl<T, S> Extend<T> for prcn_lib::prelude::HashSet<T, S> where
S: BuildHasher,
T: Eq + Hash,
[src]
S: BuildHasher,
T: Eq + Hash,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,