[−][src]Trait joinery::iter::JoinableIterator
A trait for converting Iterator
s into Join
instances or JoinIter
iterators.
This trait serves the same purpose as Joinable
, but is implemented for Iterator
types. The main difference between JoinableIterator
and Joinable
is that,
because iterators generally don't implement &T: IntoIterator
, we need a different
mechanism to allow for immutably iterating (which is required for Join
's implementation
of Display
).
Provided methods
fn join_with<S>(self, sep: S) -> Join<CloneIterator<Self>, S> where
Self: Clone,
Self: Clone,
Convert a cloneable iterator into a Join
instance. Whenever the Join
needs to immutabley iterate over the underlying iterator (for instance, when
formatting it with Display
), the underlying iterator is cloned. For most
iterator types this is a cheap operation, because the iterator contains just
a reference to the underlying collection.
Examples
use joinery::JoinableIterator; let result = (0..4).map(|x| x * 2).join_with(", ").to_string(); assert_eq!(result, "0, 2, 4, 6");
fn join_concat(self) -> Join<CloneIterator<Self>, NoSeparator> where
Self: Clone,
Self: Clone,
Convert a cloneable iterator into a Join
instance with no separator.
When formatted with Display
, the elements of the iterator will be directly
concatenated.
Examples
use joinery::JoinableIterator; let result = (0..4).map(|x| x * 2).join_concat().to_string(); assert_eq!(result, "0246");
ⓘImportant traits for JoinIter<I, S>fn iter_join_with<S>(self, sep: S) -> JoinIter<Self, S>
Create an iterator which interspeses the elements of this iterator with
a separator. See JoinIter
for more details.
Examples
use joinery::{JoinableIterator, JoinItem}; let mut iter = (0..3).map(|x| x * 2).iter_join_with(", "); assert_eq!(iter.next(), Some(JoinItem::Element(0))); assert_eq!(iter.next(), Some(JoinItem::Separator(", "))); assert_eq!(iter.next(), Some(JoinItem::Element(2))); assert_eq!(iter.next(), Some(JoinItem::Separator(", "))); assert_eq!(iter.next(), Some(JoinItem::Element(4))); assert_eq!(iter.next(), None);
Implementors
impl<T: Iterator> JoinableIterator for T
[src]
fn join_with<S>(self, sep: S) -> Join<CloneIterator<Self>, S> where
Self: Clone,
[src]
Self: Clone,
fn join_concat(self) -> Join<CloneIterator<Self>, NoSeparator> where
Self: Clone,
[src]
Self: Clone,