]>
git.proxmox.com Git - rustc.git/blob - library/core/src/iter/adapters/by_ref_sized.rs
3 /// Like `Iterator::by_ref`, but requiring `Sized` so it can forward generics.
5 /// Ideally this will no longer be required, eventually, but as can be seen in
6 /// the benchmarks (as of Feb 2022 at least) `by_ref` can have performance cost.
7 #[unstable(feature = "std_internals", issue = "none")]
9 pub struct ByRefSized
<'a
, I
>(pub &'a
mut I
);
11 #[unstable(feature = "std_internals", issue = "none")]
12 impl<I
: Iterator
> Iterator
for ByRefSized
<'_
, I
> {
16 fn next(&mut self) -> Option
<Self::Item
> {
21 fn size_hint(&self) -> (usize, Option
<usize>) {
26 fn advance_by(&mut self, n
: usize) -> Result
<(), usize> {
31 fn nth(&mut self, n
: usize) -> Option
<Self::Item
> {
36 fn fold
<B
, F
>(self, init
: B
, f
: F
) -> B
38 F
: FnMut(B
, Self::Item
) -> B
,
44 fn try_fold
<B
, F
, R
>(&mut self, init
: B
, f
: F
) -> R
46 F
: FnMut(B
, Self::Item
) -> R
,
49 self.0.try_fold(init
, f
)
53 #[unstable(feature = "std_internals", issue = "none")]
54 impl<I
: DoubleEndedIterator
> DoubleEndedIterator
for ByRefSized
<'_
, I
> {
56 fn next_back(&mut self) -> Option
<Self::Item
> {
61 fn advance_back_by(&mut self, n
: usize) -> Result
<(), usize> {
62 self.0.advance_back_by(n
)
66 fn nth_back(&mut self, n
: usize) -> Option
<Self::Item
> {
71 fn rfold
<B
, F
>(self, init
: B
, f
: F
) -> B
73 F
: FnMut(B
, Self::Item
) -> B
,
79 fn try_rfold
<B
, F
, R
>(&mut self, init
: B
, f
: F
) -> R
81 F
: FnMut(B
, Self::Item
) -> R
,
84 self.0.try_rfold(init
, f
)