LendingIteratorDyn

Trait LendingIteratorDyn 

Source
pub trait LendingIteratorDyn {
    type Item: ?Sized + HKT;

    // Required method
    fn dyn_next(&mut self) -> Option<Feed<'_, Self::Item>>;
}
Expand description

dyn-friendly (dyn-safe) version of LendingIterator.

It is automagically implemented for all types implementing LendingIterator, and, conversely, LendingIterator is implemented for dyn LendingIteratorDyn.

§Limitations

Beware that such a trait does still not play well with contexts which are generic over the “lending mode” ⚠️

So, if you intend to unify two heterogeneous LendingIterator under the same dyn LendingIteratorDyn, make sure to hard-code the dependency on the 'next-lending lifetime.

Otherwise you might have to:

§Example: dyn coercion of a fully generic LendingIterator:

  • use ::lending_iterator::prelude::*;
    
    fn coercions<'T, Item, T> (it: T)
    where
        Item : HKT,
        T : 'T + Send + Sync + LendingIterator,
        // THIS IS THE BOUND THAT YOU HAVE TO ADD TO MAKE IT WORK, for some reason:
        T : LendingIteratorDyn<Item = CanonicalHKT<Item>>, // 👈
    {
        match () {
            _ => {
                let _: Box<dyn 'T + LendingIteratorDyn<Item = CanonicalHKT<Item>>> =
                    it.dyn_boxed_auto()
                ;
            },
            _ => {
                let _: Box<dyn 'T + LendingIteratorDyn<Item = CanonicalHKT<Item>> + Send> =
                    it.dyn_boxed_auto()
                ;
            },
            _ => {
                let _: Box<dyn 'T + LendingIteratorDyn<Item = CanonicalHKT<Item>> + Sync> =
                    it.dyn_boxed_auto()
                ;
            },
            _ => {
                let _: Box<dyn 'T + LendingIteratorDyn<Item = CanonicalHKT<Item>> + Send + Sync> =
                    it.dyn_boxed_auto()
                ;
            },
        }
    }

Required Associated Types§

Source

type Item: ?Sized + HKT

Another approach to a GAT in stable Rust: use a classic associated type, but with a HKT bound on it, so that it can still be fed a lifetime parameter.

Required Methods§

Source

fn dyn_next(&mut self) -> Option<Feed<'_, Self::Item>>

A dyn-safe version of LendingIterator::next(), using [Self::Item].

Given that LendingIteratorDyn : LendingIterator, you should not need to call this function directly: calling .next() ought to work just as well.

  • That being said, if defining a LendingIteratorDyn subtrait, you may then need to directly call into it.

Trait Implementations§

Source§

impl<'next, 'usability, Item: HKT> LendingIteratorඞItem<'next> for dyn LendingIteratorDyn<Item = Item> + 'usability

Source§

type T = <Item as WithLifetime<'next>>::T

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

impl<'next, 'usability, Item: HKT> LendingIteratorඞItem<'next> for dyn LendingIteratorDyn<Item = Item> + Send + 'usability

Source§

type T = <Item as WithLifetime<'next>>::T

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

impl<'next, 'usability, Item: HKT> LendingIteratorඞItem<'next> for dyn LendingIteratorDyn<Item = Item> + Send + Sync + 'usability

Source§

type T = <Item as WithLifetime<'next>>::T

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

impl<'next, 'usability, Item: HKT> LendingIteratorඞItem<'next> for dyn LendingIteratorDyn<Item = Item> + Sync + 'usability

Source§

type T = <Item as WithLifetime<'next>>::T

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

impl<'usability, Item: HKT> LendingIterator for dyn LendingIteratorDyn<Item = Item> + 'usability

dyn LendingIteratorDyn + … : LendingIterator

Source§

fn next<'next>( self: &'next mut (dyn LendingIteratorDyn<Item = Item> + 'usability), ) -> Option<Feed<'next, Item>>

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

fn try_for_each<Err>( &mut self, f: impl FnMut(Item<'_, Self>) -> Result<(), Err>, ) -> Result<(), Err>

Source§

fn try_fold<Acc, Err>( &mut self, acc: Acc, f: impl FnMut(Acc, Item<'_, Self>) -> Result<Acc, Err>, ) -> Result<Acc, Err>

Source§

fn nth(&mut self, n: usize) -> Option<Item<'_, Self>>

Source§

impl<'usability, Item: HKT> LendingIterator for dyn LendingIteratorDyn<Item = Item> + Send + 'usability

dyn LendingIteratorDyn + … : LendingIterator

Source§

fn next<'next>( self: &'next mut (dyn LendingIteratorDyn<Item = Item> + Send + 'usability), ) -> Option<Feed<'next, Item>>

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

fn try_for_each<Err>( &mut self, f: impl FnMut(Item<'_, Self>) -> Result<(), Err>, ) -> Result<(), Err>

Source§

fn try_fold<Acc, Err>( &mut self, acc: Acc, f: impl FnMut(Acc, Item<'_, Self>) -> Result<Acc, Err>, ) -> Result<Acc, Err>

Source§

fn nth(&mut self, n: usize) -> Option<Item<'_, Self>>

Source§

impl<'usability, Item: HKT> LendingIterator for dyn LendingIteratorDyn<Item = Item> + Send + Sync + 'usability

dyn LendingIteratorDyn + … : LendingIterator

Source§

fn next<'next>( self: &'next mut (dyn LendingIteratorDyn<Item = Item> + Send + Sync + 'usability), ) -> Option<Feed<'next, Item>>

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

fn try_for_each<Err>( &mut self, f: impl FnMut(Item<'_, Self>) -> Result<(), Err>, ) -> Result<(), Err>

Source§

fn try_fold<Acc, Err>( &mut self, acc: Acc, f: impl FnMut(Acc, Item<'_, Self>) -> Result<Acc, Err>, ) -> Result<Acc, Err>

Source§

fn nth(&mut self, n: usize) -> Option<Item<'_, Self>>

Source§

impl<'usability, Item: HKT> LendingIterator for dyn LendingIteratorDyn<Item = Item> + Sync + 'usability

dyn LendingIteratorDyn + … : LendingIterator

Source§

fn next<'next>( self: &'next mut (dyn LendingIteratorDyn<Item = Item> + Sync + 'usability), ) -> Option<Feed<'next, Item>>

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

fn try_for_each<Err>( &mut self, f: impl FnMut(Item<'_, Self>) -> Result<(), Err>, ) -> Result<(), Err>

Source§

fn try_fold<Acc, Err>( &mut self, acc: Acc, f: impl FnMut(Acc, Item<'_, Self>) -> Result<Acc, Err>, ) -> Result<Acc, Err>

Source§

fn nth(&mut self, n: usize) -> Option<Item<'_, Self>>

Implementors§

Source§

impl<T: LendingIterator> LendingIteratorDyn for T

impl LendingIterator : LendingIteratorDyn

Source§

type Item = HKT<dyn for<'ඞ> WithLifetime<'ඞ, T = <T as LendingIteratorඞItem<'ඞ>>::T>>