Struct autofolder::ImplReduce
source · pub struct ImplReduce<Item> { /* private fields */ }
Expand description
The ImplReduce
type uses the ReduceTrait
for the reduce function.
This is essentially an ImplFolder
that doesn’t require an initial
value - the first value to be “reduced” is incorporated as-is instead.
Example:
use autofolder::*;
// Create a type wrapper for usize:
#[derive(Debug)]
pub struct Usize(usize);
// Create an autofolder that collects the max Usize.
let mut max = ImplReduce::<Usize>::default();
// Implement ReduceTrait for the desired ImplReduce type.
autofolder_impl_reducetrait!(|a, b| -> Usize {
Usize(std::cmp::max(a.0, b.0))
});
// We can "reduce-in" individual items.
// (note: as this is the first value, we incorporate it
// without calling the trait function)
max.reduce(Usize(3));
// We can then peek at the running output:
println!("Partial max is {:?}", max.as_ref());
// And still keep on folding by processing whole iterators:
max.extend((1..=5).map(Usize));
// And finally consume the autofolder to get the final output value:
let max = max.into_inner().unwrap();
println!("Final max is {}", max.0);
Implementations§
source§impl<Item> ImplReduce<Item>
impl<Item> ImplReduce<Item>
sourcepub fn into_inner(self) -> Option<Item>
pub fn into_inner(self) -> Option<Item>
Deconstruct self and return the inner value.
sourcepub fn reduce(&mut self, item: Item)where
Self: ReduceTrait<Item>,
pub fn reduce(&mut self, item: Item)where Self: ReduceTrait<Item>,
Reduce the given item into the current self item.
Trait Implementations§
source§impl<Item: Clone> Clone for ImplReduce<Item>
impl<Item: Clone> Clone for ImplReduce<Item>
source§fn clone(&self) -> ImplReduce<Item>
fn clone(&self) -> ImplReduce<Item>
Returns a copy 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<Item: Debug> Debug for ImplReduce<Item>
impl<Item: Debug> Debug for ImplReduce<Item>
source§impl<Item> Default for ImplReduce<Item>
impl<Item> Default for ImplReduce<Item>
source§impl<Item> Extend<Item> for ImplReduce<Item>where
ImplReduce<Item>: ReduceTrait<Item>,
impl<Item> Extend<Item> for ImplReduce<Item>where ImplReduce<Item>: ReduceTrait<Item>,
source§fn extend<It: IntoIterator<Item = Item>>(&mut self, iter: It)
fn extend<It: IntoIterator<Item = Item>>(&mut self, iter: It)
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<Item> From<Item> for ImplReduce<Item>
impl<Item> From<Item> for ImplReduce<Item>
source§impl<Item> FromIterator<Item> for ImplReduce<Item>where
ImplReduce<Item>: ReduceTrait<Item>,
impl<Item> FromIterator<Item> for ImplReduce<Item>where ImplReduce<Item>: ReduceTrait<Item>,
source§fn from_iter<It: IntoIterator<Item = Item>>(iter: It) -> Self
fn from_iter<It: IntoIterator<Item = Item>>(iter: It) -> Self
Creates a value from an iterator. Read more
impl<Item: Copy> Copy for ImplReduce<Item>
Auto Trait Implementations§
impl<Item> RefUnwindSafe for ImplReduce<Item>where Item: RefUnwindSafe,
impl<Item> Send for ImplReduce<Item>where Item: Send,
impl<Item> Sync for ImplReduce<Item>where Item: Sync,
impl<Item> Unpin for ImplReduce<Item>where Item: Unpin,
impl<Item> UnwindSafe for ImplReduce<Item>where Item: UnwindSafe,
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