| 1 | //! Joinery iterator and related types and traits |
| 2 | |
| 3 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{ |
| 4 | fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#}, |
| 5 | iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#, |
| 6 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/, |
| 7 | }; |
| 8 | |
| 9 | #[cfg(feature = "nightly")] |
| 10 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::TrustedLenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/TrustedLen#, opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#}; |
| 11 | |
| 12 | use craterust-analyzer cargo joinery 3.1.0 crate/::{ |
| 13 | joinrust-analyzer cargo joinery 3.1.0 join/::{Joinrust-analyzer cargo joinery 3.1.0 join/Join#, Joinablerust-analyzer cargo joinery 3.1.0 join/Joinable#}, |
| 14 | separatorsrust-analyzer cargo joinery 3.1.0 separators/::NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#, |
| 15 | }; |
| 16 | |
| 17 | /// Specialized helper struct to allow adapting any [`Iterator`] into a [`Join`]. |
| 18 | /// |
| 19 | /// [`Join`] requires the underlying object to be `&T: IntoIterator`, so that |
| 20 | /// it can be iterated over when formatting via [`Display`]. This works fine for |
| 21 | /// collection types like [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html), |
| 22 | /// but it doesn't work for arbitrary iterators. However, because many iterators |
| 23 | /// are cheaply clonable (because they often just contain a reference to the |
| 24 | /// underlying sequence), we can use this adapter to create an `&T: IntoIterator` |
| 25 | /// type which can be displayed by `Join`. |
| 26 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 27 | #[repr(transparent)] |
| 28 | pub struct CloneIteratorrust-analyzer cargo joinery 3.1.0 iter/CloneIterator#<I>(I); |
| 29 | |
| 30 | impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for CloneIteratorrust-analyzer cargo joinery 3.1.0 iter/CloneIterator#<I> { |
| 31 | type IntoIterrust-analyzer cargo joinery 3.1.0 iter/impl#[`CloneIterator<I>`][IntoIterator]IntoIter# = I; |
| 32 | type Itemrust-analyzer cargo joinery 3.1.0 iter/impl#[`CloneIterator<I>`][IntoIterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#; |
| 33 | |
| 34 | /// Convert the adapter back into the underlying iterator. |
| 35 | fn into_iterrust-analyzer cargo joinery 3.1.0 iter/impl#[`CloneIterator<I>`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`CloneIterator<I>`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# { |
| 36 | self.0rust-analyzer cargo joinery 3.1.0 iter/CloneIterator#0. |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | impl<'a, I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for &'a CloneIteratorrust-analyzer cargo joinery 3.1.0 iter/CloneIterator#<I> { |
| 41 | type IntoIterrust-analyzer cargo joinery 3.1.0 iter/impl#[`&'a CloneIterator<I>`][IntoIterator]IntoIter# = I; |
| 42 | type Itemrust-analyzer cargo joinery 3.1.0 iter/impl#[`&'a CloneIterator<I>`][IntoIterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#; |
| 43 | |
| 44 | /// Create a referential iterator by cloning the underlying iterator. Note |
| 45 | /// that this will have the same `Item` type as the underlying iterator, |
| 46 | /// rather than references to those items. |
| 47 | fn into_iterrust-analyzer cargo joinery 3.1.0 iter/impl#[`&'a CloneIterator<I>`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`&'a CloneIterator<I>`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# { |
| 48 | self.0rust-analyzer cargo joinery 3.1.0 iter/CloneIterator#0..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /// A trait for converting [`Iterator`]s into [`Join`] instances or [`JoinIter`] |
| 53 | /// iterators. |
| 54 | /// |
| 55 | /// This trait serves the same purpose as [`Joinable`], but is implemented for `Iterator` |
| 56 | /// types. The main difference between [`JoinableIterator`] and [`Joinable`] is that, |
| 57 | /// because iterators generally don't implement `&T: IntoIterator`, we need a different |
| 58 | /// mechanism to allow for immutably iterating (which is required for [`Join`]'s implementation |
| 59 | /// of [`Display`]). |
| 60 | pub trait JoinableIteratorrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# { |
| 61 | /// Convert a cloneable iterator into a [`Join`] instance. Whenever the [`Join`] |
| 62 | /// needs to immutabley iterate over the underlying iterator (for instance, when |
| 63 | /// formatting it with [`Display`]), the underlying iterator is cloned. For most |
| 64 | /// iterator types this is a cheap operation, because the iterator contains just |
| 65 | /// a reference to the underlying collection. |
| 66 | /// |
| 67 | /// # Examples |
| 68 | /// |
| 69 | /// ``` |
| 70 | /// use joinery::JoinableIterator; |
| 71 | /// |
| 72 | /// let result = (0..4).map(|x| x * 2).join_with(", ").to_string(); |
| 73 | /// |
| 74 | /// assert_eq!(result, "0, 2, 4, 6"); |
| 75 | /// ``` |
| 76 | fn join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#join_with().<S>(self, sep: S) -> Joinrust-analyzer cargo joinery 3.1.0 join/Join#<CloneIteratorrust-analyzer cargo joinery 3.1.0 iter/CloneIterator#<Self>, S> |
| 77 | where |
| 78 | Self: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 79 | { |
| 80 | CloneIteratorrust-analyzer cargo joinery 3.1.0 iter/CloneIterator#(self).join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().(sep) |
| 81 | } |
| 82 | |
| 83 | /// Convert a [cloneable][Clone] iterator into a [`Join`] instance with no separator. |
| 84 | /// When formatted with [`Display`], the elements of the iterator will be directly |
| 85 | /// concatenated. |
| 86 | /// # Examples |
| 87 | /// |
| 88 | /// ``` |
| 89 | /// use joinery::JoinableIterator; |
| 90 | /// |
| 91 | /// let result = (0..4).map(|x| x * 2).join_concat().to_string(); |
| 92 | /// |
| 93 | /// assert_eq!(result, "0246"); |
| 94 | /// ``` |
| 95 | fn join_concatrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#join_concat().(self) -> Joinrust-analyzer cargo joinery 3.1.0 join/Join#<CloneIteratorrust-analyzer cargo joinery 3.1.0 iter/CloneIterator#<Self>, NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#> |
| 96 | where |
| 97 | Self: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 98 | { |
| 99 | self.join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#join_with().(NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#) |
| 100 | } |
| 101 | |
| 102 | /// Create an iterator which interspeses the elements of this iterator with |
| 103 | /// a separator. See [`JoinIter`] for more details. |
| 104 | /// |
| 105 | /// # Examples |
| 106 | /// |
| 107 | /// ``` |
| 108 | /// use joinery::{JoinableIterator, JoinItem}; |
| 109 | /// |
| 110 | /// let mut iter = (0..3).map(|x| x * 2).iter_join_with(", "); |
| 111 | /// |
| 112 | /// assert_eq!(iter.next(), Some(JoinItem::Element(0))); |
| 113 | /// assert_eq!(iter.next(), Some(JoinItem::Separator(", "))); |
| 114 | /// assert_eq!(iter.next(), Some(JoinItem::Element(2))); |
| 115 | /// assert_eq!(iter.next(), Some(JoinItem::Separator(", "))); |
| 116 | /// assert_eq!(iter.next(), Some(JoinItem::Element(4))); |
| 117 | /// assert_eq!(iter.next(), None); |
| 118 | /// ``` |
| 119 | fn iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().<S>(self, sep: S) -> JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<Self, S> { |
| 120 | JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#::newrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`]new().(self, sep) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | impl<T: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> JoinableIteratorrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator# for T {} |
| 125 | |
| 126 | /// Enum representing the elements of a [`JoinIter`]. |
| 127 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 128 | pub enum JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<T, S> { |
| 129 | /// An element from the underlying iterator |
| 130 | Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(T), |
| 131 | /// A separator between two elements |
| 132 | Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(S), |
| 133 | } |
| 134 | |
| 135 | impl<T, S> JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<T, S> { |
| 136 | /// Convert a [`JoinItem`] into a common type `R`, in the case where both |
| 137 | /// `T` and `S` can be converted to `R`. Unfortunately, due to potentially |
| 138 | /// conflicting implementations, we can't implement [`Into<R>`][Into] for |
| 139 | /// [`JoinItem`]. |
| 140 | pub fn intorust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinItem<T, S>`]into().<R>(self) -> R |
| 141 | where |
| 142 | T: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<R>, |
| 143 | S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<R>, |
| 144 | { |
| 145 | match self { |
| 146 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) => el.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 147 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(sep) => sep.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | impl<R, T: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<R>, S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<R>> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<R> for JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<T, S> { |
| 153 | /// Get a reference to a common type `R` from a [`JoinItem`], in the case where |
| 154 | /// both `T` and `S` implement [`AsRef<R>`][AsRef] |
| 155 | fn as_refrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinItem<T, S>`][`AsRef<R>`]as_ref().(&self) -> &R { |
| 156 | match self { |
| 157 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) => el.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), |
| 158 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(sep) => sep.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | impl<R, T: AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<R>, S: AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<R>> AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<R> for JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<T, S> { |
| 164 | /// Get a mutable reference to a common type `R` from a [`JoinItem`], in the |
| 165 | /// case where both `T` and `S` implement [`AsMut<R>`][AsMut] |
| 166 | fn as_mutrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinItem<T, S>`][`AsMut<R>`]as_mut().(&mut self) -> &mut R { |
| 167 | match self { |
| 168 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) => el.as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#as_mut().(), |
| 169 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(sep) => sep.as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#as_mut().(), |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | impl<T: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, S: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<T, S> { |
| 175 | fn fmtrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinItem<T, S>`][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 176 | match self { |
| 177 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) => el.fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(f), |
| 178 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(sep) => sep.fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(f), |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 184 | enum JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#<T> { |
| 185 | /// Unconditionally yield the first item from the inner iterator |
| 186 | Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial#, |
| 187 | |
| 188 | /// Yield a separator if there's an item in the inner iterator |
| 189 | Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator#, |
| 190 | |
| 191 | /// We got an item from the iterator and yielded a separator, so yield |
| 192 | /// an item |
| 193 | Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(T), |
| 194 | } |
| 195 | |
| 196 | /// An iterator for a [`Join`]. |
| 197 | /// |
| 198 | /// Emits the elements of the [`Join`]'s underlying iterator, interspersed with |
| 199 | /// its separator. Note that it uses [`clone`][Clone::clone] to generate copies |
| 200 | /// of the separator while iterating, but also keep in mind that in most cases |
| 201 | /// the [`JoinItem`] instance will have a trivially cloneable separator, such |
| 202 | /// as [`&`](https://doc.rust-lang.org/std/primitive.reference.html)[`str`][str] |
| 203 | /// or [`char`]. |
| 204 | /// |
| 205 | /// # Examples |
| 206 | /// |
| 207 | /// Via [`IntoIterator`]: |
| 208 | /// |
| 209 | /// ``` |
| 210 | /// use joinery::{Joinable, JoinItem}; |
| 211 | /// |
| 212 | /// let join = vec![1, 2, 3].join_with(" "); |
| 213 | /// let mut join_iter = join.into_iter(); |
| 214 | /// |
| 215 | /// assert_eq!(join_iter.next(), Some(JoinItem::Element(1))); |
| 216 | /// assert_eq!(join_iter.next(), Some(JoinItem::Separator(" "))); |
| 217 | /// assert_eq!(join_iter.next(), Some(JoinItem::Element(2))); |
| 218 | /// assert_eq!(join_iter.next(), Some(JoinItem::Separator(" "))); |
| 219 | /// assert_eq!(join_iter.next(), Some(JoinItem::Element(3))); |
| 220 | /// assert_eq!(join_iter.next(), None); |
| 221 | /// ``` |
| 222 | /// |
| 223 | /// Via [`iter_join_with`][JoinableIterator::iter_join_with]: |
| 224 | /// |
| 225 | /// ``` |
| 226 | /// use joinery::{JoinableIterator, JoinItem}; |
| 227 | /// |
| 228 | /// let mut iter = (0..6) |
| 229 | /// .filter(|x| x % 2 == 0) |
| 230 | /// .map(|x| x * 2) |
| 231 | /// .iter_join_with(", "); |
| 232 | /// |
| 233 | /// assert_eq!(iter.next(), Some(JoinItem::Element(0))); |
| 234 | /// assert_eq!(iter.next(), Some(JoinItem::Separator(", "))); |
| 235 | /// assert_eq!(iter.next(), Some(JoinItem::Element(4))); |
| 236 | /// assert_eq!(iter.next(), Some(JoinItem::Separator(", "))); |
| 237 | /// assert_eq!(iter.next(), Some(JoinItem::Element(8))); |
| 238 | /// assert_eq!(iter.next(), None); |
| 239 | /// ``` |
| 240 | #[must_use] |
| 241 | pub struct JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<Iter: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, Sep> { |
| 242 | iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter.: Iter, |
| 243 | seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep.: Sep, |
| 244 | staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state.: JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#<Iter::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>, |
| 245 | } |
| 246 | |
| 247 | impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, S> JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<I, S> { |
| 248 | /// Construct a new [`JoinIter`] using an iterator and a separator |
| 249 | fn newrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`]new().(iter: I, sep: S) -> Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`] { |
| 250 | JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter# { |
| 251 | iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter., |
| 252 | seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep., |
| 253 | staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state.: JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial#, |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, S> JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<I, S> { |
| 259 | /// Check if the next iteration of this iterator will (try to) return a |
| 260 | /// separator. Note that this does not check if the underlying iterator is |
| 261 | /// empty, so the next `next` call could still return `None`. |
| 262 | /// |
| 263 | /// # Examples |
| 264 | /// |
| 265 | /// ``` |
| 266 | /// use joinery::{JoinableIterator, JoinItem}; |
| 267 | /// |
| 268 | /// let mut join_iter = (0..3).join_with(", ").into_iter(); |
| 269 | /// |
| 270 | /// assert_eq!(join_iter.is_sep_next(), false); |
| 271 | /// join_iter.next(); |
| 272 | /// assert_eq!(join_iter.is_sep_next(), true); |
| 273 | /// join_iter.next(); |
| 274 | /// assert_eq!(join_iter.is_sep_next(), false); |
| 275 | /// ``` |
| 276 | #[inline] |
| 277 | pub fn is_sep_nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`]is_sep_next().(&self) -> bool { |
| 278 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state., JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator#) |
| 279 | } |
| 280 | |
| 281 | /// Get a reference to the separator. |
| 282 | #[inline] |
| 283 | pub fn seprust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`]sep().(&self) -> &S { |
| 284 | &self.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep. |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | impl<I: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, S: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<I, S> |
| 289 | where |
| 290 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 291 | { |
| 292 | fn fmtrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 293 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("JoinIter") |
| 294 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("iter", &self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter.) |
| 295 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("sep", &self.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep.) |
| 296 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("state", &self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state.) |
| 297 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | impl<I: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, S: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<I, S> |
| 302 | where |
| 303 | 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#, // Needed because we use a peekable iterator |
| 304 | { |
| 305 | fn clonerust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Clone]clone().(&self) -> Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Clone] { |
| 306 | JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter# { |
| 307 | iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter.: self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), |
| 308 | seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep.: self.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), |
| 309 | staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state.: self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state..clonerust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIterState<T>`][Clone]clone().(), |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | fn clone_fromrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Clone]clone_from().(&mut self, source: &Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Clone]) { |
| 314 | self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..clone_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone_from().(&source.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter.); |
| 315 | self.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep..clone_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone_from().(&source.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep.); |
| 316 | self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state..clone_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone_from().(&source.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state.); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /// Get the size of a [`JoinIter`], given the size of the underlying iterator. If |
| 321 | /// next_sep is true, the next element in the [`JoinIter`] will be the separator. |
| 322 | /// Return None in the event of an overflow. This logic is provided as a separate |
| 323 | /// function in the hopes that it will aid compiler optimization, and also with |
| 324 | /// the intention that in the future it will be a `const fn`. |
| 325 | #[inline] |
| 326 | fn join_sizerust-analyzer cargo joinery 3.1.0 iter/join_size().<T>(iter_size: usize, state: &JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#<T>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 327 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().state { |
| 328 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial# => match iter_size { |
| 329 | 0 => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0), |
| 330 | _ => (iter_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1).checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(2)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(1), |
| 331 | }, |
| 332 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator# => iter_size.checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(2), |
| 333 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(..) => iter_size.checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(2)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(1), |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, S: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<I, S> { |
| 338 | type Itemrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]Item# = JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#, S>; |
| 339 | |
| 340 | /// Advance to the next item in the Join. This will either be the next |
| 341 | /// element in the underlying iterator, or a clone of the separator. |
| 342 | // We tag it inline in the hopes that the compiler can optimize loops into |
| 343 | // (mostly) branchless versions, similar to `(Join as Display)::fmt` |
| 344 | #[inline] |
| 345 | fn nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 346 | match memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state., JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator#) { |
| 347 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial# => self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#), |
| 348 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator# => self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|element| { |
| 349 | self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state. = JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(element); |
| 350 | JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(self.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) |
| 351 | }), |
| 352 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(element) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(element)), |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | fn size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 357 | let (min, max) = self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(); |
| 358 | |
| 359 | let min = join_sizerust-analyzer cargo joinery 3.1.0 iter/join_size().(min, &self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state.).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::usizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX.); |
| 360 | let max = max.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|max| join_sizerust-analyzer cargo joinery 3.1.0 iter/join_size().(max, &self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state.)); |
| 361 | |
| 362 | (min, max) |
| 363 | } |
| 364 | |
| 365 | fn countrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]count().(self) -> usize |
| 366 | where |
| 367 | Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 368 | { |
| 369 | match self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state. { |
| 370 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial# => (self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2).saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1), |
| 371 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator# => self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2, |
| 372 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(_) => self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | fn lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> |
| 377 | where |
| 378 | Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 379 | { |
| 380 | self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter. |
| 381 | .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().() |
| 382 | .orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(match self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state. { |
| 383 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial# | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 384 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(item) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item), |
| 385 | }) |
| 386 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#) |
| 387 | } |
| 388 | |
| 389 | fn foldrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]fold().<B, F>(mut self, init: B, mut func: F) -> B |
| 390 | where |
| 391 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B, |
| 392 | { |
| 393 | let accum = match self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state. { |
| 394 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial# => match self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() { |
| 395 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return init, |
| 396 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element) => func(init, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(element)), |
| 397 | }, |
| 398 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator# => init, |
| 399 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(element) => func(init, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(element)), |
| 400 | }; |
| 401 | |
| 402 | self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(accum, move |accum, element| { |
| 403 | let accum = func(accum, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(self.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().())); |
| 404 | func(accum, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(element)) |
| 405 | }) |
| 406 | } |
| 407 | |
| 408 | #[cfg(feature = "nightly")] |
| 409 | fn try_foldrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]try_fold().<B, F, R>(&mut self, init: B, mut func: F) -> R |
| 410 | where |
| 411 | Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 412 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> R, |
| 413 | R: Tryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#Output# = B>, |
| 414 | { |
| 415 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#; |
| 416 | |
| 417 | let accum = match memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state., JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator#) { |
| 418 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Initialrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Initial# => match self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() { |
| 419 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return R::from_outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#from_output().(init), |
| 420 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element) => func(init, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(element))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch()., |
| 421 | }, |
| 422 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Separator# => init, |
| 423 | JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(element) => func(init, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(element))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch()., |
| 424 | }; |
| 425 | |
| 426 | self.iterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#iter..try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_fold().(accum, |accum, element| { |
| 427 | match func(accum, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(self.seprust-analyzer cargo joinery 3.1.0 iter/JoinIter#sep..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().())).branchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/Try#branch().() { |
| 428 | ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Breakrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Break#(err) => { |
| 429 | self.staterust-analyzer cargo joinery 3.1.0 iter/JoinIter#state. = JoinIterStaterust-analyzer cargo joinery 3.1.0 iter/JoinIterState#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinIterState#Element#(element); |
| 430 | R::from_residualrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/try_trait/FromResidual#from_residual().(err) |
| 431 | } |
| 432 | ControlFlowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#::Continuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/control_flow/ControlFlow#Continue#(accum) => func(accum, JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(element)), |
| 433 | } |
| 434 | }) |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | impl<I: FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#, S: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<I, S> {} |
| 439 | |
| 440 | #[cfg(feature = "nightly")] |
| 441 | unsafe impl<I: TrustedLenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/TrustedLen#, S: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> TrustedLenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/TrustedLen# for JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<I, S> {} |
| 442 | |
| 443 | #[cfg(test)] |
| 444 | mod testsrust-analyzer cargo joinery 3.1.0 iter/tests/ { |
| 445 | use superrust-analyzer cargo joinery 3.1.0 iter/::JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::*; |
| 446 | use superrust-analyzer cargo joinery 3.1.0 iter/::JoinableIteratorrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#; |
| 447 | |
| 448 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 449 | fn empty_iterrust-analyzer cargo joinery 3.1.0 iter/tests/empty_iter().() { |
| 450 | let mut join_iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#0).iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(", "); |
| 451 | |
| 452 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 453 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 454 | } |
| 455 | |
| 456 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 457 | fn singlerust-analyzer cargo joinery 3.1.0 iter/tests/single().() { |
| 458 | let mut join_iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1).iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(", "); |
| 459 | |
| 460 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(0))); |
| 461 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 462 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 463 | } |
| 464 | |
| 465 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 466 | fn fewrust-analyzer cargo joinery 3.1.0 iter/tests/few().() { |
| 467 | let mut join_iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#3).iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(", "); |
| 468 | |
| 469 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(0))); |
| 470 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(", "))); |
| 471 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(1))); |
| 472 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(", "))); |
| 473 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(2))); |
| 474 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 475 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 476 | } |
| 477 | |
| 478 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 479 | fn regular_size_hintrust-analyzer cargo joinery 3.1.0 iter/tests/regular_size_hint().() { |
| 480 | let mut join_iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#10).iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(", "); |
| 481 | |
| 482 | for size in (0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#19).revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() { |
| 483 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (size, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(size))); |
| 484 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 485 | } |
| 486 | |
| 487 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 488 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 489 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0))); |
| 490 | } |
| 491 | |
| 492 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 493 | fn large_size_hintrust-analyzer cargo joinery 3.1.0 iter/tests/large_size_hint().() { |
| 494 | let join_iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#usize::max_valuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]max_value().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().10).iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(", "); |
| 495 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (usize::max_valuerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]max_value().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 496 | } |
| 497 | |
| 498 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 499 | fn threshold_size_hintrust-analyzer cargo joinery 3.1.0 iter/tests/threshold_size_hint().() { |
| 500 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::usizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX. as usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX.; |
| 501 | let usize_threshold = (usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1; |
| 502 | |
| 503 | let mut join_iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#usize_threshold rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1).iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(", "); |
| 504 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 505 | |
| 506 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 507 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)); |
| 508 | |
| 509 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 510 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX.))); |
| 511 | |
| 512 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 513 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.size_hintrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]size_hint().(), (usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX. -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(usize_maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core legacy_int_modules/usize/MAX. -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1))); |
| 514 | } |
| 515 | |
| 516 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 517 | fn partial_iterationrust-analyzer cargo joinery 3.1.0 iter/tests/partial_iteration().() { |
| 518 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 519 | |
| 520 | let mut join_iter = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#3).iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(' '); |
| 521 | |
| 522 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 523 | |
| 524 | let rest: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = join_iter.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 525 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 526 | rest, |
| 527 | [Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(' '), Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(1), Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(' '), Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(2),] |
| 528 | ); |
| 529 | } |
| 530 | |
| 531 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 532 | fn foldrust-analyzer cargo joinery 3.1.0 iter/tests/fold().() { |
| 533 | let content = [1, 2, 3]; |
| 534 | let join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(4); |
| 535 | |
| 536 | let sum = join_iter.foldrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]fold().(0, |accum, next| match next { |
| 537 | Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) => accum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add().el, |
| 538 | Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(sep) => accum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().sep, |
| 539 | }); |
| 540 | |
| 541 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, 14); |
| 542 | } |
| 543 | |
| 544 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 545 | fn partial_foldrust-analyzer cargo joinery 3.1.0 iter/tests/partial_fold().() { |
| 546 | let content = [1, 2, 3, 4]; |
| 547 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(1); |
| 548 | |
| 549 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 550 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 551 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().(); |
| 552 | |
| 553 | let sum = join_iter.foldrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]fold().(0, |accum, next| match next { |
| 554 | Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) => accum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add().el, |
| 555 | Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(sep) => accum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().sep, |
| 556 | }); |
| 557 | |
| 558 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, 9); |
| 559 | } |
| 560 | |
| 561 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 562 | fn try_foldrust-analyzer cargo joinery 3.1.0 iter/tests/try_fold().() { |
| 563 | let content = [1, 2, 0, 3]; |
| 564 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(1); |
| 565 | |
| 566 | let result = join_iter.try_foldrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]try_fold().(0, |accum, next| match next { |
| 567 | Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(sep) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(accum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().sep), |
| 568 | Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().el rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(accum), |
| 569 | Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(el) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(accum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<&i32>`]add().el), |
| 570 | }); |
| 571 | |
| 572 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(5)); |
| 573 | } |
| 574 | |
| 575 | // This test exists because implementing JoinIter::try_fold in terms of |
| 576 | // JoinIter.iter::try_fold is non trivial, and the naive (incorrect) implementation |
| 577 | // fails this test. |
| 578 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 579 | fn partial_try_foldrust-analyzer cargo joinery 3.1.0 iter/tests/partial_try_fold().() { |
| 580 | let content = [1, 2, 3]; |
| 581 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(1); |
| 582 | |
| 583 | let _ = join_iter.try_foldrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]try_fold().(1, |_, next| match next { |
| 584 | Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(_) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1), |
| 585 | Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 586 | }); |
| 587 | |
| 588 | // At this point, the remaining elements in the iterator SHOULD be E(2), S(1), E(3) |
| 589 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.countrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]count().(), 3); |
| 590 | } |
| 591 | |
| 592 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 593 | fn last_emptyrust-analyzer cargo joinery 3.1.0 iter/tests/last_empty().() { |
| 594 | let content: [i32; 0] = []; |
| 595 | let join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 596 | |
| 597 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 598 | } |
| 599 | |
| 600 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 601 | fn last_onlyrust-analyzer cargo joinery 3.1.0 iter/tests/last_only().() { |
| 602 | let content = [1]; |
| 603 | let join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 604 | |
| 605 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&1))); |
| 606 | } |
| 607 | |
| 608 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 609 | fn last_initialrust-analyzer cargo joinery 3.1.0 iter/tests/last_initial().() { |
| 610 | let content = [1, 2, 3]; |
| 611 | let join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 612 | |
| 613 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&3))); |
| 614 | } |
| 615 | |
| 616 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 617 | fn last_seprust-analyzer cargo joinery 3.1.0 iter/tests/last_sep().() { |
| 618 | let content = [1, 2, 3]; |
| 619 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 620 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 621 | |
| 622 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&3))); |
| 623 | } |
| 624 | |
| 625 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 626 | fn last_elementrust-analyzer cargo joinery 3.1.0 iter/tests/last_element().() { |
| 627 | let content = [1, 2, 3]; |
| 628 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 629 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 630 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 631 | |
| 632 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&3))); |
| 633 | } |
| 634 | |
| 635 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 636 | fn last_sep_2rust-analyzer cargo joinery 3.1.0 iter/tests/last_sep_2().() { |
| 637 | let content = [1, 2]; |
| 638 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 639 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 640 | |
| 641 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&2))); |
| 642 | } |
| 643 | |
| 644 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 645 | fn last_element_2rust-analyzer cargo joinery 3.1.0 iter/tests/last_element_2().() { |
| 646 | let content = [1, 2]; |
| 647 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 648 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 649 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 650 | |
| 651 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&2))); |
| 652 | } |
| 653 | |
| 654 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 655 | fn last_emptiedrust-analyzer cargo joinery 3.1.0 iter/tests/last_emptied().() { |
| 656 | let content = [1, 2]; |
| 657 | let mut join_iter = content.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(0); |
| 658 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 659 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 660 | join_iter.nextrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 661 | |
| 662 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(join_iter.lastrust-analyzer cargo joinery 3.1.0 iter/impl#[`JoinIter<I, S>`][Iterator]last().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 663 | } |
| 664 | } |