pub struct FromFn<Item, State, Next> where
    Item: HKT,
    Next: FnMut(&mut State) -> Option<Feed<'_, Item>>, 
{ pub state: State, pub next: Next, pub _phantom: PhantomData<fn(_: &mut State) -> Option<Feed<'_, Item>>>, }
Expand description

The impl LendingIterator returned by from_fn().

Example

  • use ::lending_iterator::prelude::*;
    
    struct Person {
        name: String,
        age: u8,
    }
    
    fn example (person: &mut Person)
      -> impl '_ + LendingIterator
    /* or:
      -> impl '_ + LendingIteratorDyn<Item = HKT!(&str)>
     */
    {
        lending_iterator::FromFn::<HKT!(&str), _, _> {
            state: person,
            next: |p| if p.age > 0 {
                Some(&p.name)
            } else {
                None
            },
            _phantom: <_>::default(),
        }
    }

Fields

state: State

The state owned by this LendingIterator.

  • Think of Self within a manual implementation of the trait;

  • Think of repeat_mut().

next: Next

The “fn next()” of a “manual implementation of the trait”.

Trick: since it’s only required to be a closure, this Next closure can capture state on its own, provided it does not need to lend from it.

This can lead to slightly more lightweight FromFn / from_fn calls:

  • put the lent / borrowed state inside .state,
  • let the rest of the state be implicitly move-captured by this closure.
_phantom: PhantomData<fn(_: &mut State) -> Option<Feed<'_, Item>>>

The signature of fn next in a PhantomData.

Trait Implementations

Query the next() Item of this Self iterator. Read more

Convenience method: same as .map(), but for hard-coding the HKT parameter to HKTRef<R> = HKT!(&R). Read more

Convenience method: same as .map(), but for hard-coding the HKT parameter to HKTRefMut<R> = HKT!(&mut R). Read more

Convenience shorthand for .map…(…).into_iter(). Read more

Convenience method: same as .filter_map(), but for hard-coding the HKT parameter to HKTRef<R> = HKT!(&R). Read more

Convenience method: same as .filter_map(), but for hard-coding the HKT parameter to HKTRefMut<R> = HKT!(&mut R). Read more

Convenience shorthand for .filter_map…(…).into_iter(). Read more

Convert a Self : LendingIterator into an Iterator, provided Self::Item<'_> does not depend on '_. Read more

Available on crate feature alloc only.

Converts this LendingIterator into a Box<dyn LendingIteratorDyn…>. Read more

Available on crate feature alloc only.

Converts this LendingIterator into a Box<dyn LendingIteratorDyn…>. Read more

The “output” of this whole hand-rolled GAT: think of LendingIteratorඞItem<'lt>::T as of LendingIterator::Item<'lt>. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.