| 1 | //! Core join type and related traits |
| 2 | |
| 3 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::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/, 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#}; |
| 4 | |
| 5 | #[cfg(feature = "token-stream")] |
| 6 | use {proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, quoterust-analyzer cargo quote 1.0.47 crate/::ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#}; |
| 7 | |
| 8 | use craterust-analyzer cargo joinery 3.1.0 crate/::{ |
| 9 | iterrust-analyzer cargo joinery 3.1.0 iter/::{JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#, JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#, JoinableIteratorrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#}, |
| 10 | separatorsrust-analyzer cargo joinery 3.1.0 separators/::NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#, |
| 11 | }; |
| 12 | |
| 13 | /// A trait for converting collections into [`Join`] instances. |
| 14 | /// |
| 15 | /// This trait is implemented for all referentially iterable types; that is, |
| 16 | /// for all types for which `&T: IntoIterator`. See [`join_with`][Joinable::join_with] |
| 17 | /// for an example of its usage. |
| 18 | pub trait Joinablerust-analyzer cargo joinery 3.1.0 join/Joinable#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# { |
| 19 | type Collectionrust-analyzer cargo joinery 3.1.0 join/Joinable#Collection#; |
| 20 | /// Combine this object with a separator to create a new [`Join`] instance. |
| 21 | /// Note that the separator does not have to share the same type as the |
| 22 | /// iterator's values. |
| 23 | /// |
| 24 | /// # Examples |
| 25 | /// |
| 26 | /// ``` |
| 27 | /// use joinery::Joinable; |
| 28 | /// |
| 29 | /// let parts = vec!["this", "is", "a", "sentence"]; |
| 30 | /// let join = parts.join_with(' '); |
| 31 | /// assert_eq!(join.to_string(), "this is a sentence"); |
| 32 | /// ``` |
| 33 | fn join_withrust-analyzer cargo joinery 3.1.0 join/Joinable#join_with().<S>(self, sep: S) -> Joinrust-analyzer cargo joinery 3.1.0 join/Join#<Self::Collectionrust-analyzer cargo joinery 3.1.0 join/Joinable#Collection#, S>; |
| 34 | |
| 35 | /// Join this object with an [empty separator](NoSeparator). When rendered |
| 36 | /// with [`Display`], the underlying elements will be directly concatenated. |
| 37 | /// Note that the separator, while empty, is still present, and will show |
| 38 | /// up if you iterate this instance. |
| 39 | /// |
| 40 | /// # Examples |
| 41 | /// |
| 42 | /// ``` |
| 43 | /// use joinery::Joinable; |
| 44 | /// |
| 45 | /// let parts = vec!['a', 'b', 'c', 'd', 'e']; |
| 46 | /// let join = parts.join_concat(); |
| 47 | /// assert_eq!(join.to_string(), "abcde"); |
| 48 | /// ``` |
| 49 | fn join_concatrust-analyzer cargo joinery 3.1.0 join/Joinable#join_concat().(self) -> Joinrust-analyzer cargo joinery 3.1.0 join/Join#<Self::Collectionrust-analyzer cargo joinery 3.1.0 join/Joinable#Collection#, NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#> { |
| 50 | self.join_withrust-analyzer cargo joinery 3.1.0 join/Joinable#join_with().(NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | impl<T> Joinablerust-analyzer cargo joinery 3.1.0 join/Joinable# for T |
| 55 | where |
| 56 | for<'a> &'a T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 57 | { |
| 58 | type Collectionrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]Collection# = Selfrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]; |
| 59 | |
| 60 | fn join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().<S>(self, sep: S) -> Joinrust-analyzer cargo joinery 3.1.0 join/Join#<Selfrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable], S> { |
| 61 | Joinrust-analyzer cargo joinery 3.1.0 join/Join# { |
| 62 | collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection.: self, |
| 63 | seprust-analyzer cargo joinery 3.1.0 join/Join#sep., |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /// A trait for using a separator to produce a [`Join`]. |
| 69 | /// |
| 70 | /// This trait provides a more python-style interface for performing joins. |
| 71 | /// Rather use [`collection.join_with`][Joinable::join_with], you can instead |
| 72 | /// use: |
| 73 | /// |
| 74 | /// ``` |
| 75 | /// use joinery::Separator; |
| 76 | /// |
| 77 | /// let join = ", ".separate([1, 2, 3, 4]); |
| 78 | /// assert_eq!(join.to_string(), "1, 2, 3, 4"); |
| 79 | /// ``` |
| 80 | /// |
| 81 | /// By default, [`Separator`] is implemented for [`char`] and [`&str`][str], as |
| 82 | /// well as all the separator types in `separators`. |
| 83 | /// |
| 84 | /// Note that any type can be used as a separator in a [`Join`] when |
| 85 | /// creating one via [`Joinable::join_with`]. The [`Separator`] trait and its |
| 86 | /// implementations on [`char`] and [`&str`][str] are provided simply as |
| 87 | /// a convenience. |
| 88 | pub trait Separatorrust-analyzer cargo joinery 3.1.0 join/Separator#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# { |
| 89 | fn separaterust-analyzer cargo joinery 3.1.0 join/Separator#separate().<T: Joinablerust-analyzer cargo joinery 3.1.0 join/Joinable#>(self, collection: T) -> Joinrust-analyzer cargo joinery 3.1.0 join/Join#<T::Collectionrust-analyzer cargo joinery 3.1.0 join/Joinable#Collection#, Self> { |
| 90 | collection.join_withrust-analyzer cargo joinery 3.1.0 join/Joinable#join_with().(self) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | impl Separatorrust-analyzer cargo joinery 3.1.0 join/Separator# for char {} |
| 95 | impl<'a> Separatorrust-analyzer cargo joinery 3.1.0 join/Separator# for &'a str {} |
| 96 | |
| 97 | /// The primary data structure for representing a joined sequence. |
| 98 | /// |
| 99 | /// It contains a collection and a separator, and represents the elements of the |
| 100 | /// collection with the separator dividing each element. A collection is defined |
| 101 | /// as any type for which `&T: IntoIterator`; that is, any time for which references |
| 102 | /// to the type are iterable. |
| 103 | /// |
| 104 | /// A [`Join`] is created with [`Joinable::join_with`], [`Separator::separate`], or |
| 105 | /// [`JoinableIterator::join_with`]. Its main use is an implementation of [`Display`], |
| 106 | /// which writes out the elements of the underlying collection, separated by the |
| 107 | /// separator. It also implements [`IntoIterator`], using a [`JoinIter`]. |
| 108 | /// |
| 109 | /// # Examples |
| 110 | /// |
| 111 | /// Writing via [`Display`]: |
| 112 | /// |
| 113 | /// ``` |
| 114 | /// use joinery::Joinable; |
| 115 | /// use std::fmt::Write; |
| 116 | /// |
| 117 | /// let content = [1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 118 | /// let join = content.join_with(", "); |
| 119 | /// |
| 120 | /// let mut buffer = String::new(); |
| 121 | /// write!(buffer, "Numbers: {}", join); |
| 122 | /// |
| 123 | /// assert_eq!(buffer, "Numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9"); |
| 124 | /// |
| 125 | /// // Don't forget that `Display` gives to `ToString` for free! |
| 126 | /// assert_eq!(join.to_string(), "1, 2, 3, 4, 5, 6, 7, 8, 9") |
| 127 | /// ``` |
| 128 | /// |
| 129 | /// Iterating via [`IntoIterator`]: |
| 130 | /// |
| 131 | /// ``` |
| 132 | /// use joinery::{Separator, JoinItem}; |
| 133 | /// |
| 134 | /// let content = [0, 1, 2]; |
| 135 | /// let join = ", ".separate(content); |
| 136 | /// let mut join_iter = (&join).into_iter(); |
| 137 | /// |
| 138 | /// assert_eq!(join_iter.next(), Some(JoinItem::Element(&0))); |
| 139 | /// assert_eq!(join_iter.next(), Some(JoinItem::Separator(&", "))); |
| 140 | /// assert_eq!(join_iter.next(), Some(JoinItem::Element(&1))); |
| 141 | /// assert_eq!(join_iter.next(), Some(JoinItem::Separator(&", "))); |
| 142 | /// assert_eq!(join_iter.next(), Some(JoinItem::Element(&2))); |
| 143 | /// assert_eq!(join_iter.next(), None); |
| 144 | /// ``` |
| 145 | #[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:)] |
| 146 | #[must_use] |
| 147 | pub struct Joinrust-analyzer cargo joinery 3.1.0 join/Join#<C, S> { |
| 148 | collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection.: C, |
| 149 | seprust-analyzer cargo joinery 3.1.0 join/Join#sep.: S, |
| 150 | } |
| 151 | |
| 152 | impl<C, S> Joinrust-analyzer cargo joinery 3.1.0 join/Join#<C, S> { |
| 153 | /// Get a reference to the separator. |
| 154 | pub fn seprust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`]sep().(&self) -> &S { |
| 155 | &self.seprust-analyzer cargo joinery 3.1.0 join/Join#sep. |
| 156 | } |
| 157 | |
| 158 | /// Get a reference to the underlying collection. |
| 159 | pub fn collectionrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`]collection().(&self) -> &C { |
| 160 | &self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection. |
| 161 | } |
| 162 | |
| 163 | /// Get a mutable reference to the underlying collection |
| 164 | pub fn collection_mutrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`]collection_mut().(&mut self) -> &mut C { |
| 165 | &mut self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection. |
| 166 | } |
| 167 | |
| 168 | /// Consume the join, and return the underlying collection. |
| 169 | pub fn into_collectionrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`]into_collection().(self) -> C { |
| 170 | self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection. |
| 171 | } |
| 172 | |
| 173 | /// Consume `self` and return underlying collection and separator. |
| 174 | pub fn into_partsrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`]into_parts().(self) -> (C, S) { |
| 175 | (self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection., self.seprust-analyzer cargo joinery 3.1.0 join/Join#sep.) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | impl<C, 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 Joinrust-analyzer cargo joinery 3.1.0 join/Join#<C, S> |
| 180 | where |
| 181 | for<'a> &'a C: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 182 | for<'a> <&'a C as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, |
| 183 | { |
| 184 | /// Format the joined collection, by writing out each element of the |
| 185 | /// collection, separated by the separator. |
| 186 | fn fmtrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, 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# { |
| 187 | let mut iter = self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection..into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(); |
| 188 | |
| 189 | match iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() { |
| 190 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 191 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first) => { |
| 192 | first.fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 193 | |
| 194 | iter.try_for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_for_each().(move |element| { |
| 195 | self.seprust-analyzer cargo joinery 3.1.0 join/Join#sep..fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 196 | element.fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#fmt().(f) |
| 197 | }) |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | impl<C: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, S: 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 Joinrust-analyzer cargo joinery 3.1.0 join/Join#<C, S> { |
| 204 | type IntoIterrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`][IntoIterator]IntoIter# = JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<C::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#, S>; |
| 205 | type Itemrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`][IntoIterator]Item# = JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<C::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#, S>; |
| 206 | |
| 207 | /// Create a consuming iterator from a `Join`. This iterator consumes the |
| 208 | /// elements of the underlying collection, and intersperses them with clones |
| 209 | /// of the separator. See the [`JoinIter`] documentation for more details. |
| 210 | fn into_iterrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# { |
| 211 | self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection..into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(self.seprust-analyzer cargo joinery 3.1.0 join/Join#sep.) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | impl<'a, C, S> IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator# for &'a Joinrust-analyzer cargo joinery 3.1.0 join/Join#<C, S> |
| 216 | where |
| 217 | &'a C: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 218 | { |
| 219 | type IntoIterrust-analyzer cargo joinery 3.1.0 join/impl#[`&'a Join<C, S>`][IntoIterator]IntoIter# = JoinIterrust-analyzer cargo joinery 3.1.0 iter/JoinIter#<<&'a C as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#, &'a S>; |
| 220 | type Itemrust-analyzer cargo joinery 3.1.0 join/impl#[`&'a Join<C, S>`][IntoIterator]Item# = JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#<<&'a C as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#, &'a S>; |
| 221 | |
| 222 | /// Create a referential iterator over the join. This iterator iterates |
| 223 | /// over references to the underlying collection, interspersed with references |
| 224 | /// to the separator. See the [`JoinIter`] documentation for more details. |
| 225 | fn into_iterrust-analyzer cargo joinery 3.1.0 join/impl#[`&'a Join<C, S>`][IntoIterator]into_iter().(self) -> Selfrust-analyzer cargo joinery 3.1.0 join/impl#[`&'a Join<C, S>`][IntoIterator]::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter# { |
| 226 | self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection..into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().iter_join_withrust-analyzer cargo joinery 3.1.0 iter/JoinableIterator#iter_join_with().(&self.seprust-analyzer cargo joinery 3.1.0 join/Join#sep.) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | #[cfg(feature = "token-stream")] |
| 231 | impl<C, S> ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens# for Joinrust-analyzer cargo joinery 3.1.0 join/Join#<C, S> |
| 232 | where |
| 233 | for<'a> &'a C: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 234 | for<'a> <&'a C as IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#>::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#, |
| 235 | S: ToTokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#, |
| 236 | { |
| 237 | fn to_tokensrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`][ToTokens]to_tokens().(&self, tokens: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#) { |
| 238 | let mut iter = self.collectionrust-analyzer cargo joinery 3.1.0 join/Join#collection..into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(); |
| 239 | if 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().() { |
| 240 | first.to_tokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#to_tokens().(tokens); |
| 241 | |
| 242 | iter.for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(move |item| { |
| 243 | self.seprust-analyzer cargo joinery 3.1.0 join/Join#sep..to_tokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#to_tokens().(tokens); |
| 244 | item.to_tokensrust-analyzer cargo quote 1.0.47 to_tokens/ToTokens#to_tokens().(tokens); |
| 245 | }) |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | #[cfg(test)] |
| 251 | mod testsrust-analyzer cargo joinery 3.1.0 join/tests/ { |
| 252 | |
| 253 | use superrust-analyzer cargo joinery 3.1.0 join/::{Joinablerust-analyzer cargo joinery 3.1.0 join/Joinable#, Separatorrust-analyzer cargo joinery 3.1.0 join/Separator#}; |
| 254 | |
| 255 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 256 | fn emptyrust-analyzer cargo joinery 3.1.0 join/tests/empty().() { |
| 257 | let data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 258 | let join = data.join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().(", "); |
| 259 | let result = join.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 260 | |
| 261 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, ""); |
| 262 | } |
| 263 | |
| 264 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 265 | fn singlerust-analyzer cargo joinery 3.1.0 join/tests/single().() { |
| 266 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Hello"]; |
| 267 | let join = data.join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().(", "); |
| 268 | let result = join.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 269 | |
| 270 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "Hello"); |
| 271 | } |
| 272 | |
| 273 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 274 | fn simple_joinrust-analyzer cargo joinery 3.1.0 join/tests/simple_join().() { |
| 275 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["This", "is", "a", "sentence"]; |
| 276 | let join = data.join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().(' '); |
| 277 | let result = join.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 278 | |
| 279 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "This is a sentence"); |
| 280 | } |
| 281 | |
| 282 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 283 | fn join_via_separatorrust-analyzer cargo joinery 3.1.0 join/tests/join_via_separator().() { |
| 284 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["This", "is", "a", "sentence"]; |
| 285 | let join = ' '.separaterust-analyzer cargo joinery 3.1.0 join/Separator#separate().(data); |
| 286 | let result = join.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 287 | |
| 288 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "This is a sentence"); |
| 289 | } |
| 290 | |
| 291 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 292 | fn iterrust-analyzer cargo joinery 3.1.0 join/tests/iter().() { |
| 293 | use craterust-analyzer cargo joinery 3.1.0 crate/::iterrust-analyzer cargo joinery 3.1.0 iter/::JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#; |
| 294 | |
| 295 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Hello", "World"]; |
| 296 | let join = data.join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().(' '); |
| 297 | let mut iter = join.into_iterrust-analyzer cargo joinery 3.1.0 join/impl#[`Join<C, S>`][IntoIterator]into_iter().(); |
| 298 | |
| 299 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#("Hello"))); |
| 300 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(' '))); |
| 301 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#("World"))); |
| 302 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#); |
| 303 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#); |
| 304 | } |
| 305 | |
| 306 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 307 | fn ref_iterrust-analyzer cargo joinery 3.1.0 join/tests/ref_iter().() { |
| 308 | use craterust-analyzer cargo joinery 3.1.0 crate/::iterrust-analyzer cargo joinery 3.1.0 iter/::JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#; |
| 309 | |
| 310 | let data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Hello", "World"]; |
| 311 | let join = data.join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().(' '); |
| 312 | let mut iter = (&join).into_iterrust-analyzer cargo joinery 3.1.0 join/impl#[`&'a Join<C, S>`][IntoIterator]into_iter().(); |
| 313 | |
| 314 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&"Hello"))); |
| 315 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Separatorrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Separator#(&' '))); |
| 316 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#(JoinItemrust-analyzer cargo joinery 3.1.0 iter/JoinItem#::Elementrust-analyzer cargo joinery 3.1.0 iter/JoinItem#Element#(&"World"))); |
| 317 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#); |
| 318 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(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#); |
| 319 | } |
| 320 | |
| 321 | #[cfg(feature = "token-stream")] |
| 322 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 323 | fn to_tokensrust-analyzer cargo joinery 3.1.0 join/tests/to_tokens().() { |
| 324 | use craterust-analyzer cargo joinery 3.1.0 crate/::separatorsrust-analyzer cargo joinery 3.1.0 separators/::NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#; |
| 325 | use quoterust-analyzer cargo quote 1.0.47 crate/::quoterust-analyzer cargo quote 1.0.47 quote!; |
| 326 | |
| 327 | let functions = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 328 | quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 329 | fn test1() {} |
| 330 | }, |
| 331 | quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 332 | fn test2() {} |
| 333 | }, |
| 334 | ]; |
| 335 | let join = functions.join_withrust-analyzer cargo joinery 3.1.0 join/impl#[T][Joinable]join_with().(NoSeparatorrust-analyzer cargo joinery 3.1.0 separators/NoSeparator#); |
| 336 | |
| 337 | let result = quoterust-analyzer cargo quote 1.0.47 quote!! { #join }; |
| 338 | let target = quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 339 | fn test1() {} |
| 340 | fn test2() {} |
| 341 | }; |
| 342 | |
| 343 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), target.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 344 | } |
| 345 | } |