Struct autofolder::ImplFolder
source · pub struct ImplFolder<Output, Item> { /* private fields */ }
Expand description
The ImplFolder
type uses the FolderTrait
for the folding function.
- Pros:
- Cons:
- Folding function can only use types defined in the user crate, which is a limitation of using traits.
- Each parameterized
ImplFolder
, defined by the pair of types, can only have one folding function.
Example:
use autofolder::*;
// Create a type wrapper for usize:
pub struct Usize(usize);
// Create an autofolder that sums `u16` items into an `Usize` output.
let mut sum = ImplFolder::<Usize, u16>::new(Usize(7));
// Implement FolderTrait for the desired ImplFolder type.
autofolder_impl_foldertrait!(|a: Usize, b: u16| {
Usize(a.0 + b as usize)
});
// We can "fold-in" individual items:
sum.fold(3);
// We can then peek at the running output:
println!("Partial sum is {}", sum.as_ref().0);
// And still keep on folding by processing whole iterators:
sum.extend((1..=5));
// And finally consume the autofolder to get the final output value:
let total = sum.into_inner();
println!("Total sum is {}", total.0);
Implementations§
source§impl<Output, Item> ImplFolder<Output, Item>
impl<Output, Item> ImplFolder<Output, Item>
sourcepub fn into_inner(self) -> Output
pub fn into_inner(self) -> Output
Deconstruct self and return the inner value.
sourcepub fn fold(&mut self, item: Item)where
Self: FolderTrait<Output, Item>,
pub fn fold(&mut self, item: Item)where Self: FolderTrait<Output, Item>,
Folds an individual value into self.
Trait Implementations§
source§impl<Output, Item> AsRef<Output> for ImplFolder<Output, Item>
impl<Output, Item> AsRef<Output> for ImplFolder<Output, Item>
source§impl<Output: Clone, Item: Clone> Clone for ImplFolder<Output, Item>
impl<Output: Clone, Item: Clone> Clone for ImplFolder<Output, Item>
source§fn clone(&self) -> ImplFolder<Output, Item>
fn clone(&self) -> ImplFolder<Output, 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<Output, Item> Default for ImplFolder<Output, Item>where
Output: Default,
impl<Output, Item> Default for ImplFolder<Output, Item>where Output: Default,
source§impl<Output, Item> Extend<Item> for ImplFolder<Output, Item>where
ImplFolder<Output, Item>: FolderTrait<Output, Item>,
impl<Output, Item> Extend<Item> for ImplFolder<Output, Item>where ImplFolder<Output, Item>: FolderTrait<Output, 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<Output, Item> From<Output> for ImplFolder<Output, Item>
impl<Output, Item> From<Output> for ImplFolder<Output, Item>
source§impl<Output, Item> FromIterator<Item> for ImplFolder<Output, Item>where
Output: Default,
ImplFolder<Output, Item>: FolderTrait<Output, Item>,
impl<Output, Item> FromIterator<Item> for ImplFolder<Output, Item>where Output: Default, ImplFolder<Output, Item>: FolderTrait<Output, 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<Output: Copy, Item: Copy> Copy for ImplFolder<Output, Item>
Auto Trait Implementations§
impl<Output, Item> RefUnwindSafe for ImplFolder<Output, Item>where Item: RefUnwindSafe, Output: RefUnwindSafe,
impl<Output, Item> Send for ImplFolder<Output, Item>where Item: Send, Output: Send,
impl<Output, Item> Sync for ImplFolder<Output, Item>where Item: Sync, Output: Sync,
impl<Output, Item> Unpin for ImplFolder<Output, Item>where Item: Unpin, Output: Unpin,
impl<Output, Item> UnwindSafe for ImplFolder<Output, Item>where Item: UnwindSafe, Output: 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