[−][src]Struct joinery::join::Join
The primary data structure for representing a joined sequence.
It contains a collection and a separator, and represents the elements of the
collection with the separator dividing each element. A collection is defined
as any type for which &T: IntoIterator
; that is, any time for which references
to the type are iterable.
A Join
is created with Joinable::join_with
, Separator::separate
, or
JoinableIterator::join_with
. Its main use is an implementation of Display
,
which writes out the elements of the underlying collection, separated by the
separator. It also implements IntoIterator
, using a JoinIter
.
Examples
Writing via Display
:
use joinery::Joinable; use std::fmt::Write; let content = [1, 2, 3, 4, 5, 6, 7, 8, 9]; let join = content.join_with(", "); let mut buffer = String::new(); write!(buffer, "Numbers: {}", join); assert_eq!(buffer, "Numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9"); // Don't forget that `Display` gives to `ToString` for free! assert_eq!(join.to_string(), "1, 2, 3, 4, 5, 6, 7, 8, 9")
Iterating via IntoIterator
:
use joinery::{Separator, JoinItem}; let content = [0, 1, 2]; 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<C, S> Join<C, S>
[src]
pub fn sep(&self) -> &S
[src]
Get a reference to the separator.
pub fn collection(&self) -> &C
[src]
Get a reference to the underlying collection.
pub fn collection_mut(&mut self) -> &mut C
[src]
Get a mutable reference to the underlying collection
pub fn into_collection(self) -> C
[src]
Consume the join, and return the underlying collection.
pub fn into_parts(self) -> (C, S)
[src]
Consume self
and return underlying collection and separator.
Trait Implementations
impl<C: Clone, S: Clone> Clone for Join<C, S>
[src]
fn clone(&self) -> Join<C, S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<C: Debug, S: Debug> Debug for Join<C, S>
[src]
impl<C, S: Display> Display for Join<C, S> where
&'a C: IntoIterator,
<&'a C as IntoIterator>::Item: Display<'a>,
[src]
&'a C: IntoIterator,
<&'a C as IntoIterator>::Item: Display<'a>,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Format the joined collection, by writing out each element of the collection, separated by the separator.
impl<C: PartialEq, S: PartialEq> PartialEq<Join<C, S>> for Join<C, S>
[src]
impl<C: Eq, S: Eq> Eq for Join<C, S>
[src]
impl<C: IntoIterator, S: Clone> IntoIterator for Join<C, S>
[src]
type IntoIter = JoinIter<C::IntoIter, S>
Which kind of iterator are we turning this into?
type Item = JoinItem<C::Item, S>
The type of the elements being iterated over.
fn into_iter(self) -> Self::IntoIter
[src]
Create a consuming iterator from a Join
. This iterator consumes the
elements of the underlying collection, and intersperses them with clones
of the separator. See the JoinIter
documentation for more details.
impl<'a, C, S> IntoIterator for &'a Join<C, S> where
&'a C: IntoIterator,
[src]
&'a C: IntoIterator,
type IntoIter = JoinIter<<&'a C as IntoIterator>::IntoIter, &'a S>
Which kind of iterator are we turning this into?
type Item = JoinItem<<&'a C as IntoIterator>::Item, &'a S>
The type of the elements being iterated over.
fn into_iter(self) -> Self::IntoIter
[src]
Create a referential iterator over the join. This iterator iterates
over references to the underlying collection, interspersed with references
to the separator. See the JoinIter
documentation for more details.
Auto Trait Implementations
impl<C, S> Send for Join<C, S> where
C: Send,
S: Send,
C: Send,
S: Send,
impl<C, S> Sync for Join<C, S> where
C: Sync,
S: Sync,
C: Sync,
S: Sync,
Blanket Implementations
impl<T> Joinable for T where
&'a T: IntoIterator,
[src]
&'a T: IntoIterator,
type Collection = T
fn join_with<S>(Self, S) -> Join<T, S>
[src]
fn join_concat(self) -> Join<Self::Collection, NoSeparator>
[src]
impl<T> From for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,