File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
library/core/src/iter/adapters Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 11use crate :: iter:: adapters:: SourceIter ;
2- use crate :: iter:: { FusedIterator , TrustedLen } ;
2+ use crate :: iter:: { FusedIterator , PeekableIterator , TrustedLen } ;
33use crate :: ops:: { ControlFlow , Try } ;
44
55/// An iterator with a `peek()` that returns an optional reference to the next
@@ -322,6 +322,14 @@ impl<I: Iterator> Peekable<I> {
322322#[ unstable( feature = "trusted_len" , issue = "37572" ) ]
323323unsafe impl < I > TrustedLen for Peekable < I > where I : TrustedLen { }
324324
325+ #[ unstable( feature = "peekable_iterator" , issue = "132973" ) ]
326+ impl < I : Iterator > PeekableIterator for Peekable < I > {
327+ fn peek_with < T > ( & mut self , func : impl for < ' a > FnOnce ( Option < & ' a Self :: Item > ) -> T ) -> T {
328+ let tmp = self . peek ( ) ;
329+ func ( tmp. as_ref ( ) )
330+ }
331+ }
332+
325333#[ unstable( issue = "none" , feature = "inplace_iteration" ) ]
326334unsafe impl < I : Iterator > SourceIter for Peekable < I >
327335where
You can’t perform that action at this time.
0 commit comments