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]

Get a reference to the separator.

Get a reference to the underlying iterator.

Consume self and return the separator and underlying iterator.

impl<I: Clone, S> Join<I, S>
[src]

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]

Consume self, writing it to a Formatter. The Display trait requires &self, so this method is provided in the event that you can't or don't want to clone the underlying iterator.

impl<I: Iterator + Clone, S> Join<I, S>
[src]

Important traits for JoinIter<I, S>

Create an iterator for this Join. This iterator uses a clone of the underlying iterator, but a reference to the separator.

Trait Implementations

impl<Iter: Debug, Sep: Debug> Debug for Join<Iter, Sep>
[src]

Formats the value using the given formatter. Read more

impl<Iter: Clone, Sep: Clone> Clone for Join<Iter, Sep>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<Iter: PartialEq, Sep: PartialEq> PartialEq for Join<Iter, Sep>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<Iter: Eq, Sep: Eq> Eq for Join<Iter, Sep>
[src]

impl<I, S> Display for Join<I, S> where
    I: Iterator + Clone,
    S: Display,
    I::Item: Display
[src]

Formats the value using the given formatter. Read more

impl<I: Iterator, S: Clone> IntoIterator for Join<I, S>
[src]

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

impl<I: Iterator, S> From<Join<I, S>> for JoinIter<I, S>
[src]

Performs the conversion.

Auto Trait Implementations

impl<Iter, Sep> Send for Join<Iter, Sep> where
    Iter: Send,
    Sep: Send

impl<Iter, Sep> Sync for Join<Iter, Sep> where
    Iter: Sync,
    Sep: Sync