Struct Min

Source
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>

Source

pub fn new(initial: Item) -> Self

Creates a new $name with the provided initial value.

Source

pub fn into_inner(self) -> Option<Item>

Deconstruct self and return the inner value.

Source

pub fn as_ref(&self) -> Option<&Item>

Returns a reference to the inner value, if there is one.

Source

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.

Source

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.

Source

pub fn eval(&mut self, item: Item)
where Item: PartialOrd,

Alias for [$name::reduce]

Source

pub fn eval_ref(&mut self, item: &Item)
where Item: PartialOrd + Clone,

Alias for [$name::reduce_ref]

Trait Implementations§

Source§

impl<Item: Clone> Clone for Min<Item>

Source§

fn clone(&self) -> Min<Item>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Item: Debug> Debug for Min<Item>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Item> Default for Min<Item>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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)

Extends a collection with the contents of an iterator. Read more
Source§

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)

🔬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,

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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 Min<Item>

Source§

fn from(item: Item) -> Self

Converts to this type from the input type.
Source§

impl<'a, Item> FromIterator<&'a Item> for Min<Item>
where Item: PartialOrd + Clone,

Source§

fn from_iter<It: IntoIterator<Item = &'a Item>>(iter: It) -> Self

Creates a value from an iterator. Read more
Source§

impl<Item> FromIterator<Item> for Min<Item>
where Item: PartialOrd,

Source§

fn from_iter<It: IntoIterator<Item = Item>>(iter: It) -> Self

Creates a value from an iterator. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.