pub struct ExtendUsing<F: ?Sized>(pub F);Expand description
Use an arbitrary FnMut type to implement Extend.
use extend_fn::ExtendUsing;
let numbers = [5, 2, 11usize];
let mut result = 1usize;
let mut extender = ExtendUsing::new(|value| result *= value);
extender.extend(numbers.iter().copied());
assert_eq!(numbers.iter().product::<usize>(), result);For cases where you are writing into an actual container and want to
transform items before their addition, consider using the
extend_map crate instead.
Tuple Fields§
§0: FImplementations§
Source§impl<F> ExtendUsing<F>
impl<F> ExtendUsing<F>
Trait Implementations§
Source§impl<F: Clone + ?Sized> Clone for ExtendUsing<F>
impl<F: Clone + ?Sized> Clone for ExtendUsing<F>
Source§fn clone(&self) -> ExtendUsing<F>
fn clone(&self) -> ExtendUsing<F>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<F: Default + ?Sized> Default for ExtendUsing<F>
impl<F: Default + ?Sized> Default for ExtendUsing<F>
Source§fn default() -> ExtendUsing<F>
fn default() -> ExtendUsing<F>
Returns the “default value” for a type. Read more
Source§impl<Item, F: ?Sized + FnMut(Item)> Extend<Item> for ExtendUsing<F>
impl<Item, F: ?Sized + FnMut(Item)> Extend<Item> for ExtendUsing<F>
Source§fn extend<I: IntoIterator<Item = Item>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Item>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<F> From<F> for ExtendUsing<F>
impl<F> From<F> for ExtendUsing<F>
Source§impl<F: Ord + ?Sized> Ord for ExtendUsing<F>
impl<F: Ord + ?Sized> Ord for ExtendUsing<F>
Source§fn cmp(&self, other: &ExtendUsing<F>) -> Ordering
fn cmp(&self, other: &ExtendUsing<F>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<F: PartialOrd + ?Sized> PartialOrd for ExtendUsing<F>
impl<F: PartialOrd + ?Sized> PartialOrd for ExtendUsing<F>
impl<F: Copy + ?Sized> Copy for ExtendUsing<F>
impl<F: Eq + ?Sized> Eq for ExtendUsing<F>
impl<F: ?Sized> StructuralPartialEq for ExtendUsing<F>
Auto Trait Implementations§
impl<F> Freeze for ExtendUsing<F>
impl<F> RefUnwindSafe for ExtendUsing<F>where
F: RefUnwindSafe + ?Sized,
impl<F> Send for ExtendUsing<F>
impl<F> Sync for ExtendUsing<F>
impl<F> Unpin for ExtendUsing<F>
impl<F> UnwindSafe for ExtendUsing<F>where
F: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more