pub struct Min<Item> { /* private fields */ }
Expand description
The Min
type uses the std::cmp::PartialOrd
trait to contain only the smallest iterated
value.
Example:
use autofolder::*;
// Create an autofolder that collects the min usize.
let mut min = Min::<usize>::default();
// We can "reduce-in" individual items.
// (note: as this is the first value, we incorporate it
// without calling the trait function)
min.reduce(3);
// `eval` does the same as `reduce`:
min.eval(2);
// We can then peek at the running output:
println!("Partial min is {:?}", min.as_ref());
// And still keep on folding by processing whole iterators:
min.extend((1..=5));
// And finally consume the autofolder to get the final output value:
let min = min.into_inner().unwrap();
println!("Final min is {}", min);
Implementations§
Source§impl<Item> Min<Item>
impl<Item> Min<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
Item: PartialOrd,
pub fn reduce(&mut self, item: Item)where
Item: PartialOrd,
Replaces the current value with the new one if the new one is greater/smaller.
Sourcepub fn reduce_ref(&mut self, item: &Item)where
Item: PartialOrd + Clone,
pub fn reduce_ref(&mut self, item: &Item)where
Item: PartialOrd + Clone,
Replaces the current value with the one behing the ref if it is greater/smaller.
This function requires the Clone
trait, but uses it only if necessary.
Sourcepub fn eval(&mut self, item: Item)where
Item: PartialOrd,
pub fn eval(&mut self, item: Item)where
Item: PartialOrd,
Alias for [$name::reduce
]
Sourcepub fn eval_ref(&mut self, item: &Item)where
Item: PartialOrd + Clone,
pub fn eval_ref(&mut self, item: &Item)where
Item: PartialOrd + Clone,
Alias for [$name::reduce_ref
]
Trait Implementations§
Source§impl<'a, Item> Extend<&'a Item> for Min<Item>where
Item: PartialOrd + Clone,
impl<'a, Item> Extend<&'a Item> for Min<Item>where
Item: PartialOrd + Clone,
Source§fn extend<It: IntoIterator<Item = &'a Item>>(&mut self, iter: It)
fn extend<It: IntoIterator<Item = &'a 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> Extend<Item> for Min<Item>where
Item: PartialOrd,
impl<Item> Extend<Item> for Min<Item>where
Item: PartialOrd,
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<'a, Item> FromIterator<&'a Item> for Min<Item>where
Item: PartialOrd + Clone,
impl<'a, Item> FromIterator<&'a Item> for Min<Item>where
Item: PartialOrd + Clone,
Source§impl<Item> FromIterator<Item> for Min<Item>where
Item: PartialOrd,
impl<Item> FromIterator<Item> for Min<Item>where
Item: PartialOrd,
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 Min<Item>
Auto Trait Implementations§
impl<Item> Freeze for Min<Item>where
Item: Freeze,
impl<Item> RefUnwindSafe for Min<Item>where
Item: RefUnwindSafe,
impl<Item> Send for Min<Item>where
Item: Send,
impl<Item> Sync for Min<Item>where
Item: Sync,
impl<Item> Unpin for Min<Item>where
Item: Unpin,
impl<Item> UnwindSafe for Min<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