Struct joinery::Join [−][src]
pub struct Join<Iter, Sep> { /* fields omitted */ }
The primary data structure for representing a joined sequence.
It contains an interator and a separator, and represents the elements of the iterator with the separator dividing each element.
A Join
is created with Joinable::join_with
or Separator::separate
.
It can be iterated, and implements Display
so that it can
be written to a writer or converted into a String
.
Examples
Writing via Display
:
use joinery::Joinable; use std::fmt::Write; let content = 0..10; let join = content.join_with(", "); let mut buffer = String::new(); write!(buffer, "Numbers: {}", join); assert_eq!(buffer, "Numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9"); // Don't forget that `Display` gives to `ToString` for free! assert_eq!(join.to_string(), "0, 1, 2, 3, 4, 5, 6, 7, 8, 9")
Iterating via IntoIterator
:
use joinery::{Separator, JoinItem}; let content = 0..3; let join = ", ".separate(content); let mut join_iter = join.into_iter(); assert_eq!(join_iter.next(), Some(JoinItem::Element(0))); assert_eq!(join_iter.next(), Some(JoinItem::Separator(", "))); assert_eq!(join_iter.next(), Some(JoinItem::Element(1))); assert_eq!(join_iter.next(), Some(JoinItem::Separator(", "))); assert_eq!(join_iter.next(), Some(JoinItem::Element(2))); assert_eq!(join_iter.next(), None);
Methods
impl<I, S> Join<I, S>
[src]
impl<I, S> Join<I, S>
pub fn sep(&self) -> &S
[src]
pub fn sep(&self) -> &S
Get a reference to the separator.
pub fn underlying_iter(&self) -> &I
[src]
pub fn underlying_iter(&self) -> &I
Get a reference to the underlying iterator.
pub fn extract_parts(self) -> (I, S)
[src]
pub fn extract_parts(self) -> (I, S)
Consume self
and return the separator and underlying iterator.
impl<I: Clone, S> Join<I, S>
[src]
impl<I: Clone, S> Join<I, S>
pub fn partial_clone(&self) -> Join<I, &S>
[src]
pub fn partial_clone(&self) -> Join<I, &S>
Create a partial clone of self
. A partial clone is a Join
instance
which contains a cloned iterator, but a reference to the original
separator. This is useful in cases where the iterator needs to be
consumed, but there's no need to perform a full clone of the separator
(e.g. if it's a String
).
Most functions which observe &self
make use of this conversion
internally, because it's necessary to consume the iterator in order to
render or iterate a Join
.
impl<I, S> Join<I, S> where
I: Iterator,
S: Display,
I::Item: Display,
[src]
impl<I, S> Join<I, S> where
I: Iterator,
S: Display,
I::Item: Display,
pub fn consume_fmt(self, f: &mut Formatter) -> Result
[src]
pub fn consume_fmt(self, f: &mut Formatter) -> Result
impl<I: Iterator + Clone, S> Join<I, S>
[src]
impl<I: Iterator + Clone, S> Join<I, S>
Trait Implementations
impl<Iter: Debug, Sep: Debug> Debug for Join<Iter, Sep>
[src]
impl<Iter: Debug, Sep: Debug> Debug for Join<Iter, Sep>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<Iter: Clone, Sep: Clone> Clone for Join<Iter, Sep>
[src]
impl<Iter: Clone, Sep: Clone> Clone for Join<Iter, Sep>
fn clone(&self) -> Join<Iter, Sep>
[src]
fn clone(&self) -> Join<Iter, Sep>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<Iter: PartialEq, Sep: PartialEq> PartialEq for Join<Iter, Sep>
[src]
impl<Iter: PartialEq, Sep: PartialEq> PartialEq for Join<Iter, Sep>
fn eq(&self, other: &Join<Iter, Sep>) -> bool
[src]
fn eq(&self, other: &Join<Iter, Sep>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Join<Iter, Sep>) -> bool
[src]
fn ne(&self, other: &Join<Iter, Sep>) -> bool
This method tests for !=
.
impl<Iter: Eq, Sep: Eq> Eq for Join<Iter, Sep>
[src]
impl<Iter: Eq, Sep: Eq> Eq for Join<Iter, Sep>
impl<I, S> Display for Join<I, S> where
I: Iterator + Clone,
S: Display,
I::Item: Display,
[src]
impl<I, S> Display for Join<I, S> where
I: Iterator + Clone,
S: Display,
I::Item: Display,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<I: Iterator, S: Clone> IntoIterator for Join<I, S>
[src]
impl<I: Iterator, S: Clone> IntoIterator for Join<I, S>
type IntoIter = JoinIter<I, S>
Which kind of iterator are we turning this into?
type Item = JoinItem<I::Item, S>
The type of the elements being iterated over.
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<I: Iterator, S> From<Join<I, S>> for JoinIter<I, S>
[src]
impl<I: Iterator, S> From<Join<I, S>> for JoinIter<I, S>