pub struct Last<T> { /* private fields */ }Expand description
A Collector that stores the last item it collects.
If no items have been collected, its Output is None;
otherwise, it is Some containing the most recently collected item.
This collector corresponds to Iterator::last().
§Examples
use better_collect::{prelude::*, Last};
let mut collector = Last::new();
assert!(collector.collect(1).is_continue());
assert!(collector.collect(2).is_continue());
assert!(collector.collect(3).is_continue());
assert_eq!(collector.finish(), Some(3));use better_collect::{prelude::*, Last};
assert_eq!(Last::<i32>::new().finish(), None);Implementations§
Trait Implementations§
Source§impl<T> Collector for Last<T>
impl<T> Collector for Last<T>
Source§fn collect(&mut self, item: T) -> ControlFlow<()>
fn collect(&mut self, item: T) -> ControlFlow<()>
Collects an item and returns a
ControlFlow indicating whether
the collector has stopped accumulating right after this operation. Read moreSource§fn finish(self) -> Self::Output
fn finish(self) -> Self::Output
Consumes the collector and returns the accumulated result. Read more
Source§fn collect_many(
&mut self,
items: impl IntoIterator<Item = Self::Item>,
) -> ControlFlow<()>
fn collect_many( &mut self, items: impl IntoIterator<Item = Self::Item>, ) -> ControlFlow<()>
Collects items from an iterator and returns a
ControlFlow indicating whether
the collector has stopped collecting right after this operation. Read moreSource§fn collect_then_finish(
self,
items: impl IntoIterator<Item = Self::Item>,
) -> Self::Output
fn collect_then_finish( self, items: impl IntoIterator<Item = Self::Item>, ) -> Self::Output
Collects items from an iterator, consumes the collector, and produces the accumulated result. Read more
Source§fn break_hint(&self) -> bool
fn break_hint(&self) -> bool
Returns a hint whether the collector has stopped accumulating. Read more
Source§fn copying(self) -> Copying<Self>
fn copying(self) -> Copying<Self>
Creates a
RefCollector that copies every collected item. Read moreSource§fn map_ref<F, T>(self, f: F) -> MapRef<Self, T, F>
fn map_ref<F, T>(self, f: F) -> MapRef<Self, T, F>
Creates a
RefCollector that calls a closure on each item by mutable reference before collecting. Read moreSource§fn take_while<F>(self, pred: F) -> TakeWhile<Self, F>
fn take_while<F>(self, pred: F) -> TakeWhile<Self, F>
Source§fn chain<C>(self, other: C) -> Chain<Self, C::IntoCollector>
fn chain<C>(self, other: C) -> Chain<Self, C::IntoCollector>
Source§fn partition<C, F>(
self,
pred: F,
other_if_false: C,
) -> Partition<Self, C::IntoCollector, F>
fn partition<C, F>( self, pred: F, other_if_false: C, ) -> Partition<Self, C::IntoCollector, F>
Source§fn unzip<C>(self, other: C) -> Unzip<Self, C::IntoCollector>where
Self: Sized,
C: IntoCollector,
fn unzip<C>(self, other: C) -> Unzip<Self, C::IntoCollector>where
Self: Sized,
C: IntoCollector,
Source§fn unbatching<T, F>(self, f: F) -> Unbatching<Self, T, F>
fn unbatching<T, F>(self, f: F) -> Unbatching<Self, T, F>
Source§fn unbatching_ref<T, F>(self, f: F) -> UnbatchingRef<Self, T, F>
fn unbatching_ref<T, F>(self, f: F) -> UnbatchingRef<Self, T, F>
Creates a
RefCollector with a custom collection logic. Read moreSource§fn map_output<T, F>(self, f: F) -> MapOutput<Self, T, F>
fn map_output<T, F>(self, f: F) -> MapOutput<Self, T, F>
Source§fn nest<C>(self, inner: C) -> Nest<Self, C::IntoCollector>
fn nest<C>(self, inner: C) -> Nest<Self, C::IntoCollector>
Available on crate feature
unstable only.Source§fn nest_exact<C>(self, inner: C) -> NestExact<Self, C::IntoCollector>
fn nest_exact<C>(self, inner: C) -> NestExact<Self, C::IntoCollector>
Available on crate feature
unstable only.Auto Trait Implementations§
impl<T> Freeze for Last<T>where
T: Freeze,
impl<T> RefUnwindSafe for Last<T>where
T: RefUnwindSafe,
impl<T> Send for Last<T>where
T: Send,
impl<T> Sync for Last<T>where
T: Sync,
impl<T> Unpin for Last<T>where
T: Unpin,
impl<T> UnwindSafe for Last<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CollectorByMut for Twhere
&'a mut T: for<'a> IntoCollector,
impl<T> CollectorByMut for Twhere
&'a mut T: for<'a> IntoCollector,
Source§type CollectorMut<'a> = <&'a mut T as IntoCollector>::IntoCollector
where
T: 'a
type CollectorMut<'a> = <&'a mut T as IntoCollector>::IntoCollector where T: 'a
Which collector being produced?
Source§fn collector_mut(&mut self) -> <T as CollectorByMut>::CollectorMut<'_>
fn collector_mut(&mut self) -> <T as CollectorByMut>::CollectorMut<'_>
Creates a
Collector from a mutable reference of a value.Source§impl<C> IntoCollector for Cwhere
C: Collector,
impl<C> IntoCollector for Cwhere
C: Collector,
Source§type IntoCollector = C
type IntoCollector = C
Which collector being produced?
Source§fn into_collector(self) -> <C as IntoCollector>::IntoCollector
fn into_collector(self) -> <C as IntoCollector>::IntoCollector
Creates a collector from a value.