Gat!() { /* proc-macro */ }
Expand description

::nougat::Gat!

You can use this macro around a type to get access to:

  • <I as LendingIterator>::Item<'lt> (if for some reason you did not like Item<'lt, I>);

  • impl for<'n> LendingIterator<Item<'n> = …>.

You can also use it in conjunction with #[apply], as in #[apply(Gat!)], to annotate an item with it so as to:

  • get the previous functionality applied to all types occurrences in that annotated item;

  • get LendingIterator<Item<'…> = …> kind of trait bounds (e.g., as a in I : … clauses, or as a super trait) to also work anywhere on the annotated item (this is something no targeted macro could ever support, due to language limitations).

Example

  • use ::lending_iterator::prelude::*;
    
    #[apply(Gat!)]
    fn my_iter_1<T> (slice: &'_ mut [T])
      -> impl '_ + for<'n> LendingIterator<Item<'n> = &'n mut [T; 2]>
    {
        windows_mut::<T, 2>(slice)
    }
    // same as:
    fn my_iter_2<T> (slice: &'_ mut [T])
      -> Gat!(impl '_ + for<'n> LendingIterator<Item<'n> = &'n mut [T; 2]>)
    {
        windows_mut::<T, 2>(slice)
    }
    
    #[apply(Gat!)]
    fn print_all<I, T> (mut iter: I)
    where
        T : ::core::fmt::Debug,
        // Trait bound on GAT
        for<'n>
            <I as LendingIterator>::Item<'n> : Send
        ,
        // Equality constraint on GAT
        I : for<'n> LendingIterator<Item<'n> = &'n mut [T; 2]>,
    {
        iter.for_each(|&mut [ref x, ref y]| {
            dbg!(x, y);
        });
    }