| 1 | use superrust-analyzer cargo itertools 0.14.0 crate/::size_hintrust-analyzer cargo itertools 0.14.0 size_hint/; |
| 2 | |
| 3 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#; |
| 4 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#; |
| 6 | |
| 7 | /// Common buffer object for the two tee halves |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 9 | struct TeeBufferrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#<A, I> { |
| 10 | backlogrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#backlog.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<A>, |
| 11 | iterrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#iter.: I, |
| 12 | /// The owner field indicates which id should read from the backlog |
| 13 | ownerrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#owner.: bool, |
| 14 | } |
| 15 | |
| 16 | /// One half of an iterator pair where both return the same elements. |
| 17 | /// |
| 18 | /// See [`.tee()`](crate::Itertools::tee) for more information. |
| 19 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 20 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 21 | pub struct Teerust-analyzer cargo itertools 0.14.0 tee/Tee#<I> |
| 22 | where |
| 23 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 24 | { |
| 25 | rcbufferrust-analyzer cargo itertools 0.14.0 tee/Tee#rcbuffer.: Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#<TeeBufferrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, I>>>, |
| 26 | idrust-analyzer cargo itertools 0.14.0 tee/Tee#id.: bool, |
| 27 | } |
| 28 | |
| 29 | pub fn newrust-analyzer cargo itertools 0.14.0 tee/new().<I>(iter: I) -> (Teerust-analyzer cargo itertools 0.14.0 tee/Tee#<I>, Teerust-analyzer cargo itertools 0.14.0 tee/Tee#<I>) |
| 30 | where |
| 31 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 32 | { |
| 33 | let buffer = TeeBufferrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer# { |
| 34 | backlogrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#backlog.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().(), |
| 35 | iterrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#iter., |
| 36 | ownerrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#owner.: false, |
| 37 | }; |
| 38 | let t1 = Teerust-analyzer cargo itertools 0.14.0 tee/Tee# { |
| 39 | rcbufferrust-analyzer cargo itertools 0.14.0 tee/Tee#rcbuffer.: Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(buffer)), |
| 40 | idrust-analyzer cargo itertools 0.14.0 tee/Tee#id.: true, |
| 41 | }; |
| 42 | let t2 = Teerust-analyzer cargo itertools 0.14.0 tee/Tee# { |
| 43 | rcbufferrust-analyzer cargo itertools 0.14.0 tee/Tee#rcbuffer.: t1.rcbufferrust-analyzer cargo itertools 0.14.0 tee/Tee#rcbuffer..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().(), |
| 44 | idrust-analyzer cargo itertools 0.14.0 tee/Tee#id.: false, |
| 45 | }; |
| 46 | (t1, t2) |
| 47 | } |
| 48 | |
| 49 | impl<I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Teerust-analyzer cargo itertools 0.14.0 tee/Tee#<I> |
| 50 | where |
| 51 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 52 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 53 | { |
| 54 | type Itemrust-analyzer cargo itertools 0.14.0 tee/impl#[`Tee<I>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#; |
| 55 | fn nextrust-analyzer cargo itertools 0.14.0 tee/impl#[`Tee<I>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 tee/impl#[`Tee<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 56 | // .borrow_mut may fail here -- but only if the user has tied some kind of weird |
| 57 | // knot where the iterator refers back to itself. |
| 58 | let mut buffer = self.rcbufferrust-analyzer cargo itertools 0.14.0 tee/Tee#rcbuffer..borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().(); |
| 59 | if buffer.ownerrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#owner. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().self.idrust-analyzer cargo itertools 0.14.0 tee/Tee#id. { |
| 60 | match buffer.backlogrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#backlog..pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_front().() { |
| 61 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {} |
| 62 | some_elt => return some_elt, |
| 63 | } |
| 64 | } |
| 65 | match buffer.iterrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() { |
| 66 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 67 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt) => { |
| 68 | buffer.backlogrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#backlog..push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().(elt.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 69 | buffer.ownerrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#owner. = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.idrust-analyzer cargo itertools 0.14.0 tee/Tee#id.; |
| 70 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt) |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | fn size_hintrust-analyzer cargo itertools 0.14.0 tee/impl#[`Tee<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 76 | let buffer = self.rcbufferrust-analyzer cargo itertools 0.14.0 tee/Tee#rcbuffer..borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow().(); |
| 77 | let sh = buffer.iterrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(); |
| 78 | |
| 79 | if buffer.ownerrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#owner. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().self.idrust-analyzer cargo itertools 0.14.0 tee/Tee#id. { |
| 80 | let log_len = buffer.backlogrust-analyzer cargo itertools 0.14.0 tee/TeeBuffer#backlog..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]len().(); |
| 81 | size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::add_scalarrust-analyzer cargo itertools 0.14.0 size_hint/add_scalar().(sh, log_len) |
| 82 | } else { |
| 83 | sh |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | impl<I> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for Teerust-analyzer cargo itertools 0.14.0 tee/Tee#<I> |
| 89 | where |
| 90 | I: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator#, |
| 91 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 92 | { |
| 93 | } |