Expand description
§lender
A lender, also called a lending iterator, is an iterator that lends mutable borrows
to the items it returns. In particular, this means that the reference to an item is
invalidated by the subsequent call to next. Niko Matsakis has an interesting
blog post
explaining a general view of giving vs. lending traits.
The typical example that cannot be written with standard Rust iterators, but is covered by lenders, is that of a lender returning mutable, overlapping windows of a slice or array.
But lenders are more general than that, as they might return items that depend on
some mutable state stored in the iterator. For example, a lender might
return references to the lines of a file reusing an internal buffer; also,
starting from an iterator on pairs of integers lexicographically sorted, a lender
might return iterators on pairs with the same first coordinate without any copying;
clearly, in all these cases any call on next would invalidate the reference
returned by the previous call.
This crate provides a lender trait and an associated library of utility methods, “utilizing” #84533 and #25860 to implement the lender design based on higher-rank trait bounds proposed by Sabrina Jewson.
Similarly to what happens with standard iterators, besides the fundamental Lender trait there is an
IntoLender trait, and methods such as for_each.
Indeed, the crate implements for Lender all of the methods of Iterator,
except partition_in_place, map_windows, and array_chunks (the latter being
replaced by
chunky),
and most methods provide the same functionality as the equivalent Iterator
method.
Notable differences in behavior include next_chunk providing a lender instead of an array
and closures requiring usage of the covar!, covar_mut!, covar_once! macros, which provide higher-ranked closure
and output covariance checks.
Turn a lender into an iterator with cloned
where lend is Clone, copied where lend is Copy,
owned where lend is ToOwned, or
iter where the lender already satisfies the restrictions of Iterator.
Turn an iterator into a lender with into_lender, which is just a pass-through, or
into_ref_lender which stores the next item and returns a reference to it. lend_iter can be used instead to safely shorten the lifetime of references
returned by an iterator, getting a lender.
§Features
The derive feature (enabled by default) provides the
for_! procedural macro
from the lender-derive crate.
§Usage
The Rust for syntax for iterating over types implementing IntoIterator will not work with lenders. The idiomatic way
of iterating over a lender is to use a while let loop, as in:
while let Some(item) = lender.next() {
// Do something with item
}Note that the expression after the equal sign cannot be a method call returning a lender, as you would iterate over the first element forever.
To simplify usage, we provide a function-like procedural macro
for_! that makes it
possible to use a for-like syntax with types implementing IntoLender:
for_!(item in into_lender {
// Do something with item
});Finally, you can use the for_each method, which takes a closure as argument, but managing lifetimes in closures can be
challenging:
lender.for_each(
covar_mut!(for<'lend> |item: &'lend mut TYPE| {
// do something with item of type TYPE
})
);§Fallible Lenders
Fallible lenders offer the same semantics of fallible
iterators, where the next method
returns a Result type, for lenders. They offer more flexibility than a
lender returning Option<Result<…>>: for example, they can short-circuit the
iteration on errors using the ? operator; moreover, some adapters are
difficult or impossible to write for a lender returning Option<Result<…>>.
The idiomatic way of iterating over a fallible lender, propagating the error, is
to use a while let loop, as in:
while let Some(item) = lender.next()? {
// Do something with item
}If you want to handle the error, you can use a three-armed match statement:
loop {
match lender.next() {
Err(e) => { /* handle error */ },
Ok(None) => { /* end of iteration */ },
Ok(Some(item)) => { /* do something with item */ },
}
}If you have a Lender you can make it into a FallibleLender with
into_fallible, and analogously for an IntoLender. You can also
obtain a fallible lender from a fallible iterator. In general, all
reasonable automatic conversions between iterators and lenders (fallible or not)
are provided.
§Binding the Lend
When writing methods accepting a Lender, to bind the
type of the returned lend you need to use a higher-rank trait bound, as in:
use lender::*;
fn read_lender<L>(mut lender: L)
where
L: Lender + for<'lend> Lending<'lend, Lend = &'lend str>,
{
let _: Option<&'_ str> = lender.next();
}You can also bind the lend using traits:
use lender::*;
fn read_lender<L>(mut lender: L)
where
L: Lender + for<'lend> Lending<'lend, Lend: AsRef<str>>,
{
let lend = lender.next();
let _: Option<&'_ str> = lend.as_ref().map(AsRef::as_ref);
}In this case, you can equivalently use the Lend type alias, which might be
more concise:
use lender::*;
fn read_lender<L>(mut lender: L)
where
L: Lender,
for<'lend> Lend<'lend, L>: AsRef<str>,
{
let lend = lender.next();
let _: Option<&'_ str> = lend.as_ref().map(AsRef::as_ref);
}§Caveats
If a dyn Lender trait object is in your future, this crate is not going
to work.
Finally, note that, as a general rule, if you can avoid using lenders, you should. You should heed the counsel of Polonius: “Neither a borrower nor a lender be”.
§Examples
Let us compute the Fibonacci numbers using mutable windows:
use ::lender::prelude::*;
use lender_derive::for_;
// Fibonacci sequence
let mut data = vec![0u32; 3 * 3];
data[1] = 1;
// Fibonacci sequence, most ergonomic usage: for_! procedural macro.
for_!(w in data.array_windows_mut::<3>() {
w[2] = w[0] + w[1];
});
assert_eq!(data, [0, 1, 1, 2, 3, 5, 8, 13, 21]);
// You can use destructuring assignments with for_!.
for_!([a, b, c] in data.array_windows_mut::<3>() {
*c = *a + *b;
});
assert_eq!(data, [0, 1, 1, 2, 3, 5, 8, 13, 21]);
// Fibonacci sequence, explicit while let loop: you MUST assign the lender to a variable.
let mut windows = data.array_windows_mut::<3>();
while let Some(w) = windows.next() {
w[2] = w[0] + w[1];
}
assert_eq!(data, [0, 1, 1, 2, 3, 5, 8, 13, 21]);
// Fibonacci sequence, for_each
data.array_windows_mut::<3>()
.for_each(|w| {
w[2] = w[0] + w[1]
});
assert_eq!(data, [0, 1, 1, 2, 3, 5, 8, 13, 21]);This is quite a contrived example, but it shows how lenders can be used to mutate a slice in place.
So, let’s look at a slightly more interesting example, LinesStr, an io::Lines with an Item of &str instead of String.
It’s a good example of borrowing from the lender itself, and also a natural use case for a fallible lender.
use std::io;
use ::lender::prelude::*;
struct LinesStr<B> {
buf: B,
line: String,
}
impl<'lend, B: io::BufRead> FallibleLending<'lend> for LinesStr<B> {
type Lend = &'lend str;
}
impl<B: io::BufRead> FallibleLender for LinesStr<B> {
type Error = io::Error;
check_covariance_fallible!();
fn next(&mut self) -> Result<Option<&'_ str>, Self::Error> {
self.line.clear();
match self.buf.read_line(&mut self.line)? {
0 => return Ok(None),
_nread => (),
};
if self.line.ends_with('\n') {
self.line.pop();
if self.line.ends_with('\r') {
self.line.pop();
}
}
Ok(Some(&self.line))
}
}
let buf = io::BufReader::with_capacity(10, "Hello\nWorld\n".as_bytes());
let mut lines = LinesStr { buf, line: String::new() };
assert_eq!(lines.next().unwrap(), Some("Hello"));
assert_eq!(lines.next().unwrap(), Some("World"));Note the check_covariance_fallible! macro invocation, which ensures that the lend is
covariant.
§Implementing Lender
To implement Lender first you’ll need to implement the Lending trait for your type.
This is the equivalent provider of Iterator::Item:
use ::lender::prelude::*;
struct StrRef<'a>(&'a str);
impl<'this, 'lend> Lending<'lend> for StrRef<'this> {
type Lend = &'lend str;
}The lifetime parameter 'lend describes the lifetime of the Lend.
It works by using under the hood a default generic of &'lend Self which induces an implicit
reference lifetime bound 'lend: 'this, which is necessary for usage of
higher-rank trait bounds with Lend.
Next, you’ll need to implement the Lender
trait for your type, the lending equivalent of Iterator.
use ::lender::prelude::*;
struct StrRef<'a>(&'a str);
impl<'this, 'lend> Lending<'lend> for StrRef<'this> {
type Lend = &'lend str;
}
impl<'this> Lender for StrRef<'this> {
check_covariance!();
fn next(&mut self) -> Option<&'_ str> {
Some(self.0)
}
}Note the check_covariance! macro invocation, which ensures that the lend is
covariant. There is an additional unsafe_assume_covariance! macro
that can be used when the lender wraps another lender to propagate covariance.
The Lend type alias can be used to avoid specifying twice the type of the lend;
combined with lifetime elision, it can make your implementations
more concise and less prone to errors:
use ::lender::prelude::*;
struct StrRef<'a>(&'a str);
impl<'this, 'lend> Lending<'lend> for StrRef<'this> {
type Lend = &'lend str;
}
impl<'this> Lender for StrRef<'this> {
check_covariance!();
fn next(&mut self) -> Option<Lend<'_, Self>> {
Some(self.0)
}
}Implementing a FallibleLender is similar, using the
check_covariance_fallible! or unsafe_assume_covariance_fallible! macros
instead.
§Why Not GATs?
Generic associated types (GATs) were introduced exactly having lending iterators as a use case in mind. With GATs, a lender trait could be easily defined as
pub trait Lender {
type Lend<'lend>: where Self: 'lend;
fn next(&mut self) -> Option<Self::Lend<'_>>;
}This looks all nice and cozy, and you can even write a full-fledged library around it. But you will hit a wall when trying to specify trait bounds on the lend type, something that can be done only using higher-rank trait bounds:
pub trait Lender {
type Lend<'lend>: where Self: 'lend;
fn next(&mut self) -> Option<Self::Lend<'_>>;
}
fn read_lender<L: Lender>(lender: L)
where for<'lend> L::Lend<'lend>: AsRef<str> {}Again, this will compile without problems, but as you try to use read_lender
with a type implementing Lender, since the where clause specifies that
that trait bound must hold for all lifetimes, that means it must be valid
for 'static, and since the lender must outlive the lend,
also the lender must be 'static. Thus, until there is some syntax that makes it
possible to restrict the lifetime variable that appears in a higher-rank trait bound,
GAT-based lending iterators are of little practical use.
§Why Isn’t CovariantLending In between Lending and Lender?
This is a very technical section, so feel free to skip it if you’re not interested in the details the design choices behind this crate.
To guarantee that the lend type is covariant in the lifetime parameter,
we use a method in the CovariantLending and Lender traits based
on CovariantProof<T>, a newtype wrapping a private PhantomData<fn() -> T>
(which is covariant in T):
fn __check_covariance<'long: 'short, 'short>(
proof: CovariantProof<<Self as Lending<'long>>::Lend>,
) -> CovariantProof<<Self as Lending<'short>>::Lend>;If this method is implemented as { proof }, then the compiler will
check that CovariantProof<Lend<'long>> is convertible to
CovariantProof<Lend<'short>>, given that 'long outlives 'short.
Since CovariantProof<T> is covariant in T, this is only possible
when Lend<'long> is a subtype of Lend<'short>, which is the
definition of covariance.
This is what the check_covariance! macro does for Lender impls.
The unsafe_assume_covariance! macro, instead, implements this method
as { unsafe { core::mem::transmute(proof) } }, which tells the
compiler to assume covariance without checking it: it is in this case a
responsibility of the programmer to ensure that covariance holds (as
the caller of an unsafe block must ensure the safety invariants).
Since the private field of CovariantProof prevents construction
outside the crate, users cannot bypass the check without unsafe.
Moreover, source factory functions and adapter constructors call
__check_covariance on the types they use, making it impossible to
circumvent the check with non-returning code (todo!(),
unimplemented!(), panic!(), loop {}, etc.).
CovariantLending is a separate trait that depends on Lending. It
is the trait required by methods that just require a Lending impl but
not a Lender impl, such as once. It forces the same type of check,
and it is automatically implemented by the lend and covariant_lend
macros.
Now, a first obvious question is: why not put this method directly in
Lending? The problem is that in the implementation of Lending for T,
the compiler can only normalize <T as Lending<'lend>>::Lend for the specific
'lend from the impl header. The __check_covariance method introduces new
lifetimes 'long and 'short and projects <Self as Lending<'long>>::Lend and
<Self as Lending<'short>>::Lend; the compiler can’t resolve these
projections because 'long/'short are not 'lend.
When __check_covariance is in Lender or CovariantLending, instead, it
works because for<'all> Lending<'all> is a supertrait for all lifetimes.
The second obvious question is: why isn’t CovariantLending as a supertrait of
Lender depending on Lending (via a for<'all> Lending<'all> bound)?
That would be logical, as there would be only one instance of
__check_covariance.
The problem is just of ergonomics: Lender is already enough complicated,
requiring a supporting Lending to specify its lend. Having a third trait in
the hierarchy would make it even more complicated to use. A macro in the vein of
check_covariance! would not help, as it would introduce surreptitiously and
invisibly an implementation of CovariantLending that Lender would depend
on later, making it hard to understand the trait hierarchy.
In the end, having CovariantLending as a separate trait is a compromise that
makes it possible to have covariance checks where needed without complicating
the Lender trait too much.
§Resources
Please check out the great resources below that helped us and many others learn about Rust and the lending iterator problem. Thank you to everyone!
- Sabrina Jewson’s Blog for her awesome blog post on why lifetime GATs are not (yet) the solution to this problem, we highly recommend reading it.
- The awesome people on the Rust Users Forum in helping us understand the borrow checker and HRTBs better and being patient with us and other aspiring rustaceans as we try to learn more about Rust.
- Daniel Henry-Mantilla for writing
lending-iteratorand many other great crates and sharing their great work. - Everyone who’s contributed to Rust for making such a great language and iterator library.
§Unsafe & Transmutes
Many patterns in lenders require polonius-emulating unsafe code, but if you see any unsafe code that can be made safe, please let us know!
Re-exports§
pub use higher_order::Covar;pub use stable_try_trait_v2 as try_trait_v2;
Modules§
- higher_
order - Types and Traits for Higher-Order Types with Covariance Checks
- prelude
Macros§
- check_
covariance - Implement the covariance check method for a
Lenderimpl with a concreteLendtype. - check_
covariance_ fallible - Implement the covariance check method for a
FallibleLenderimpl with a concreteLendtype. - covar
- Covariance-checked
Fnclosure macro. - covar_
mut - Covariance-checked
FnMutclosure macro. - covar_
once - Covariance-checked
FnOnceclosure macro. - covariant_
fallible_ lend - Defines a fallible lending type with compile-time covariance checking.
- covariant_
lend - Defines a lending type with compile-time covariance checking.
- fallible_
lend - Uses lifetime
'lendwithin type$Tto create animpl for<'lend> FallibleLending<'lend, Lend = $T>. - for_
- Syntax sugar for iterating over a
Lender. - lend
- Uses lifetime
'lendwithin type$Tto create animpl for<'lend> Lending<'lend, Lend = $T>. - unsafe_
assume_ covariance - Skips the covariance check for
Lenderimpls. - unsafe_
assume_ covariance_ fallible - Skips the covariance check for
FallibleLenderimpls.
Structs§
- Array
Windows Mut - A lender over mutable overlapping windows of a slice as fixed-size arrays.
- Chain
- A lender that chains two lenders together, one after the other.
- Chunk
- A sub-lender over elements of a chunk in a
Chunkylender. - Chunky
- A lender yielding lenders (
Chunks) returning the nextchunk_sizelends. - Cloned
- An iterator that clones the elements of an underlying lender.
- Convert
- A fallible lending iterator that wraps a normal lending
iterator over
Results. - Copied
- An iterator that copies the elements of an underlying lender.
- Cycle
- A lender that repeats endlessly.
- Empty
- A lender that yields nothing.
- Enumerate
- A lender that yields the current count and the element during iteration.
- Fallible
Empty - A fallible lender that yields nothing.
- Fallible
Flat Map - A fallible lender that maps each element to a lender, and yields the elements of the produced lenders.
- Fallible
Flatten - A fallible lender that flattens one level of nesting in a lender of lenders.
- Fallible
Intersperse - A fallible lender that inserts a separator between adjacent elements of the underlying lender.
- Fallible
Intersperse With - A fallible lender that inserts an element computed by a closure between adjacent elements of the underlying lender.
- Fallible
Once - A fallible lender that yields a value exactly once.
- Fallible
Once Err - A fallible lender that yields a single error.
- Fallible
Once With - A fallible lender that yields a single element by applying the provided closure.
- Fallible
Once With Err - A fallible lender that yields a single error by applying the provided closure.
- Fallible
Peekable - A fallible lender with a
peek()method that returns an optional reference to the next element. - Fallible
Repeat - A fallible lender that repeats an element endlessly.
- Fallible
Repeat Err - A fallible lender that endlessly repeats an error.
- Fallible
Repeat With - A fallible lender that repeats an element endlessly by applying a closure.
- Fallible
Repeat With Err - A fallible lender that endlessly repeats errors generated by a closure.
- Filter
- A lender that filters the elements of the underlying lender with a predicate.
- Filter
Map - A lender that uses a closure to optionally produce elements.
- FlatMap
- A lender that maps each element to a lender, and yields the elements of the produced lenders.
- Flatten
- A lender that flattens one level of nesting in a lender of lenders.
- From
Fallible Fn - A lender where each iteration calls the provided closure
F: FnMut(&mut St) -> Result<Option<T>, E>. - From
Fallible Iter - A lender that yields elements from a fallible iterator.
- From
Fallible Iter Ref - A fallible lender that stores each element from a fallible iterator and lends a reference to it.
- FromFn
- A lender where each iteration calls the provided closure
F: FnMut(&mut St) -> Option<T>. - From
Into Fallible Iter - An
IntoFallibleLenderthat returns lenders obtained by applyingfrom_fallible_iter()to the iterators returned by the wrappedIntoFallibleIterator. - From
Into Iter - An
IntoLenderthat returns lenders obtained by applyingfrom_iterto the iterators returned by the wrappedIntoIterator. - From
Iter - A lender that yields elements from an iterator.
- From
Iter Ref - A lender that stores each element from an iterator and lends a reference to it.
- Fuse
- A lender that yields
Noneforever after the underlying lender yieldsNoneonce. - Inspect
- A lender that calls a function with a reference to each element before yielding it.
- Intersperse
- A lender that inserts a separator between adjacent elements of the underlying lender.
- Intersperse
With - A lender that inserts an element computed by a closure between adjacent elements of the underlying lender.
- Into
Fallible - A fallible lender that wraps a normal lender.
- Iter
Iteratoradapter for anyLenderwhere multipleLends can exist at a time, allowing on-the-fly conversion into an iterator whereLendingis no longer needed or inferred.- Lend
Fallible Iter - A lender that lends elements from a fallible iterator by shortening their lifetime.
- Lend
Iter - A lender that lends elements from an iterator by shortening their lifetime.
- Map
- A lender that maps the values of the underlying lender with a closure.
- MapErr
- A fallible lender that maps the errors of the underlying lender with a closure.
- MapInto
Iter - An iterator that maps each element of the underlying lender into an owned value.
- MapWhile
- A lender that yields elements based on a predicate and maps them.
- Mutate
- A lender that calls a mutation function on each element before yielding it.
- Once
- A lender that yields an element exactly once.
- Once
With - A lender that yields a single element by applying the provided closure.
- Owned
- An iterator that converts each lent reference into an owned value.
- Peekable
- A lender with a
peek()method that returns an optional reference to the next element. - Repeat
- A lender that repeats an element endlessly.
- Repeat
With - A lender that repeats an element endlessly by applying a closure.
- Rev
- A double-ended lender with the direction inverted.
- Scan
- A lender to maintain state while lending elements from the underlying lender.
- Skip
- A lender that skips over the first
nelements of the underlying lender. - Skip
While - A lender that rejects elements while a predicate returns
true. - StepBy
- A lender for stepping the underlying lender by a custom amount.
- Take
- A lender that only yields the first
nelements of the underlying lender. - Take
While - A lender that yields elements while a predicate returns
true. - Windows
Mut - A lender over mutable overlapping windows of a slice.
- Zip
- A lender that yields pairs of elements from two underlying lenders.
Traits§
- Double
Ended Fallible Lender - The
FallibleLenderversion ofcore::iter::DoubleEndedIterator. - Double
Ended Lender - The
Lenderversion ofcore::iter::DoubleEndedIterator. - Exact
Size Fallible Lender - The
FallibleLenderversion ofcore::iter::ExactSizeIterator. - Exact
Size Lender - The
Lenderversion ofcore::iter::ExactSizeIterator. - Extend
Fallible Lender - The
FallibleLenderversion ofcore::iter::Extend. - Extend
Lender - The
Lenderversion ofcore::iter::Extend. - Fallible
Iterator Ext - Extension trait adding to
FallibleIteratorthe methodinto_fallible_lender, which turns aFallibleIteratorinto aFallibleLenderwithout allocation. - Fallible
Iterator RefExt - Extension trait adding to
FallibleIteratorthe methodinto_fallible_ref_lender, which turns aFallibleIterator<Item = T>into aFallibleLenderwithFallibleLend<'lend> = &'lend T. - Fallible
Lender - A trait for dealing with fallible lending iterators.
- Fallible
Lending - The fallible counterpart of
Lending. See its documentation for details on the HRTB implicit-bound technique used here. - From
Fallible Lender - A trait for creating a value from a
FallibleLender. - From
Lender - A trait for creating a value from a
Lender. - Fused
Fallible Lender - Marker trait that ensures that a fallible lender will always continue to
yield
Ok(None)once it has already returnedOk(None). After an error, the behavior is implementation-defined. - Fused
Lender - The
Lenderversion ofcore::iter::FusedIterator. - Into
Fallible Iterator Ext - Extension trait adding to
IntoFallibleIteratorthe methodinto_into_fallible_lender, which turns anIntoFallibleIteratorinto anIntoFallibleLenderwithout allocation. - Into
Fallible Lender - Conversion into a
FallibleLender. - Into
Iterator Ext - Extension trait adding to
IntoIteratorthe methodinto_into_lender, which turns anIntoIteratorinto anIntoLenderwithout allocation. - Into
Lender - Conversion into a
Lender. - Iterator
Ext - Extension trait adding to
Iteratorthe methodinto_lender, which turns anIteratorinto aLenderwithout allocation. - Iterator
RefExt - Extension trait adding to
Iteratorthe methodinto_ref_lender, which turns anIterator<Item = T>into aLenderwithLend<'lend> = &'lend T. - Lender
- A trait for dealing with lending iterators.
- Lending
- A trait for dealing with the ‘items’ of lending iterators.
- Product
Fallible Lender - The
FallibleLenderversion ofcore::iter::Product. - Product
Lender - The
Lenderversion ofcore::iter::Product. - SumFallible
Lender - Sums lends of a
FallibleLenderinto a single Self. - SumLender
- Sums lends of a
Lenderinto a single Self. - Tuple
Lend - Trait for lend types that can be destructured into two components, used
by
Lender::unzip()andFallibleLender::unzip(). - Windows
MutExt - Extension trait adding to slices and arrays the methods
windows_mutandarray_windows_mut.
Functions§
- array_
windows_ mut - Creates a new lender that returns mutable overlapping array windows of fixed size over a slice.
- empty
- Creates a lender that yields nothing.
- fallible_
empty - Creates a fallible lender that yields nothing.
- fallible_
once - Creates a fallible lender that yields a value exactly once.
- fallible_
once_ err - Creates a fallible lender that yields a single error.
- fallible_
once_ with - Creates a fallible lender that lazily generates a value exactly once by invoking the provided closure.
- fallible_
once_ with_ err - Creates a fallible lender that lazily generates a single error by invoking the provided closure.
- fallible_
repeat - Creates a new fallible lender that endlessly repeats a single element.
- fallible_
repeat_ err - Creates a new fallible lender that endlessly repeats an error.
- fallible_
repeat_ with - Creates a new fallible lender that repeats elements endlessly
by applying the provided closure, the repeater,
F: FnMut() -> A. - fallible_
repeat_ with_ err - Creates a new fallible lender that endlessly repeats errors generated by a closure.
- from_
fallible_ fn - Creates a fallible lender from a state and a closure
F: FnMut(&mut St) -> Result<Option<T>, E>. - from_
fallible_ iter - Creates a lender from a fallible iterator.
- from_
fallible_ iter_ ref - Creates a fallible lender that stores each element from a fallible iterator and lends a reference to it.
- from_fn
- Creates a lender from a state and a closure
F: FnMut(&mut St) -> Option<T>. - from_
into_ fallible_ iter - Creates an
IntoFallibleLenderfrom anIntoFallibleIterator. - from_
into_ iter - Creates an
IntoLenderfrom anIntoIterator. - from_
iter - Creates a lender from an iterator.
- from_
iter_ ref - Creates a lender that stores each element from an iterator and lends a reference to it.
- lend_
fallible_ iter - Creates a fallible lender from a fallible iterator
I, safely shortening the items’ lifetimes with the given lending typeL. - lend_
iter - Creates a lender from an iterator
I, safely shortening the items’ lifetimes with the given lending typeL. - once
- Creates a lender that yields an element exactly once.
- once_
with - Creates a lender that lazily generates a value exactly once by invoking the provided closure.
- repeat
- Creates a new lender that endlessly repeats a single element.
- repeat_
with - Creates a new lender that repeats elements endlessly by
applying the provided closure, the repeater,
F: FnMut() -> A. - windows_
mut - Creates a new lender that returns mutable contiguous overlapping windows of fixed size over a slice.
- zip
- Zips two lenders into a single lender of pairs.
Type Aliases§
- Fallible
Lend - A readable shorthand for the type of the items of a
FallibleLenderL. - Fallible
TryShunt Adapter - Lend
- A readable shorthand for the type of the items of a
LenderL.