| 1 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 2 | |
| 3 | /// Join the list with an 'or' before the last element of the list. |
| 4 | /// |
| 5 | /// # Examples |
| 6 | /// ``` |
| 7 | /// assert_eq!(reword::or_join(&["a", "b"]), "a or b"); |
| 8 | /// assert_eq!(reword::or_join(&["a", "b", "c"]), "a, b or c"); |
| 9 | /// ``` |
| 10 | pub fn or_joinrust-analyzer cargo reword 7.0.1 join/or_join().<I>(iter: I) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# |
| 11 | where |
| 12 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 13 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 14 | { |
| 15 | joinrust-analyzer cargo reword 7.0.1 join/join().(iter, ", ", " or ") |
| 16 | } |
| 17 | |
| 18 | /// Join the list with an 'and' before the last element of the list. |
| 19 | /// |
| 20 | /// # Examples |
| 21 | /// ``` |
| 22 | /// assert_eq!(reword::and_join(&["a", "b"]), "a and b"); |
| 23 | /// assert_eq!(reword::and_join(&["a", "b", "c"]), "a, b and c"); |
| 24 | /// ``` |
| 25 | pub fn and_joinrust-analyzer cargo reword 7.0.1 join/and_join().<I>(iter: I) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# |
| 26 | where |
| 27 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 28 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 29 | { |
| 30 | joinrust-analyzer cargo reword 7.0.1 join/join().(iter, ", ", " and ") |
| 31 | } |
| 32 | |
| 33 | fn joinrust-analyzer cargo reword 7.0.1 join/join().<I>(iter: I, mid_sep: &str, end_sep: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# |
| 34 | where |
| 35 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 36 | I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 37 | { |
| 38 | let mut iter = iter.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(); |
| 39 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() else { |
| 40 | return Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 41 | }; |
| 42 | |
| 43 | let (lower, upper) = iter.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(); |
| 44 | let mut string = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(upper.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(lower) 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().8); |
| 45 | string.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(first.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 46 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut next) = iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() else { |
| 47 | return string; |
| 48 | }; |
| 49 | |
| 50 | for peek in iter { |
| 51 | string.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(mid_sep); |
| 52 | string.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(next.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 53 | next = peek; |
| 54 | } |
| 55 | |
| 56 | string.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(end_sep); |
| 57 | string.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(next.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 58 | string |
| 59 | } |