pub trait SliceSourceCollection<T>{
// Required method
fn for_each<F>(&self, f: F)
where F: for<'a> FnMut(&'a dyn SliceSource<T>);
}
Expand description
Trait for generic access to collections of SliceSource
objects.
Collections can be either arrays, tuples, or slices of SliceSource
objects. Tuples can contain contain objects of different SliceSource
implementation types. If either the std
or unstable
features are
enabled, boxed slice
and Vec
instances can be used as slice
source collections as well.
SliceSourceCollection
on its own is only usable for Clone
and Copy
data sources. For move operations, the SliceMoveSourceCollection
subtrait provides additional functionality for moving slices out of
supported types.
Required Methods§
Sourcefn for_each<F>(&self, f: F)where
F: for<'a> FnMut(&'a dyn SliceSource<T>),
fn for_each<F>(&self, f: F)where
F: for<'a> FnMut(&'a dyn SliceSource<T>),
Calls a closure for each SliceSource
in this collection.
§Examples
use scratchpad::{SliceLike, SliceSourceCollection};
let collection = ([1, 2, 3], [4], [5, 6]);
let mut out = Vec::new();
collection.for_each(|source| {
for x in source.as_slice_like().as_element_slice() {
out.push(*x * 2);
}
});
assert_eq!(*out, [2, 4, 6, 8, 10, 12]);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.