Struct joinery::join::Join [−][src]
#[must_use]pub struct Join<C, S> { /* fields omitted */ }
Expand description
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);
Implementations
impl<C, S> Join<C, S>
[src]
impl<C, S> Join<C, S>
[src]pub fn collection(&self) -> &C
[src]
pub fn collection(&self) -> &C
[src]Get a reference to the underlying collection.
pub fn collection_mut(&mut self) -> &mut C
[src]
pub fn collection_mut(&mut self) -> &mut C
[src]Get a mutable reference to the underlying collection
pub fn into_collection(self) -> C
[src]
pub fn into_collection(self) -> C
[src]Consume the join, and return the underlying collection.
pub fn into_parts(self) -> (C, S)
[src]
pub fn into_parts(self) -> (C, S)
[src]Consume self
and return underlying collection and separator.
Trait Implementations
impl<C, S: Display> Display for Join<C, S> where
&'a C: IntoIterator,
<&'a C as IntoIterator>::Item: Display<'a>,
[src]
impl<C, S: Display> Display for Join<C, S> where
&'a C: IntoIterator,
<&'a C as IntoIterator>::Item: Display<'a>,
[src]impl<C: IntoIterator, S: Clone> IntoIterator for Join<C, S>
[src]
impl<C: IntoIterator, S: Clone> IntoIterator for Join<C, S>
[src]impl<'a, C, S> IntoIterator for &'a Join<C, S> where
&'a C: IntoIterator,
[src]
impl<'a, C, S> IntoIterator for &'a Join<C, S> where
&'a C: IntoIterator,
[src]impl<C, S> ToTokens for Join<C, S> where
&'a C: IntoIterator,
<&'a C as IntoIterator>::Item: ToTokens<'a>,
S: ToTokens,
[src]
impl<C, S> ToTokens for Join<C, S> where
&'a C: IntoIterator,
<&'a C as IntoIterator>::Item: ToTokens<'a>,
S: ToTokens,
[src]fn to_tokens(&self, tokens: &mut TokenStream)
[src]
fn to_tokens(&self, tokens: &mut TokenStream)
[src]Write self
to the given TokenStream
. Read more
fn to_token_stream(&self) -> TokenStream
[src]
fn to_token_stream(&self) -> TokenStream
[src]Convert self
directly into a TokenStream
object. Read more
fn into_token_stream(self) -> TokenStream
[src]
fn into_token_stream(self) -> TokenStream
[src]Convert self
directly into a TokenStream
object. Read more
impl<C: Eq, S: Eq> Eq for Join<C, S>
[src]
impl<C, S> StructuralEq for Join<C, S>
[src]
impl<C, S> StructuralPartialEq for Join<C, S>
[src]
Auto Trait Implementations
impl<C, S> RefUnwindSafe for Join<C, S> where
C: RefUnwindSafe,
S: RefUnwindSafe,
C: RefUnwindSafe,
S: RefUnwindSafe,
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,
impl<C, S> Unpin for Join<C, S> where
C: Unpin,
S: Unpin,
C: Unpin,
S: Unpin,
impl<C, S> UnwindSafe for Join<C, S> where
C: UnwindSafe,
S: UnwindSafe,
C: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Joinable for T where
&'a T: for<'a> IntoIterator,
[src]
impl<T> Joinable for T where
&'a T: for<'a> IntoIterator,
[src]type Collection = T
fn join_concat(self) -> Join<Self::Collection, NoSeparator>
[src]
fn join_concat(self) -> Join<Self::Collection, NoSeparator>
[src]Join this object with an empty separator. When rendered
with Display
, the underlying elements will be directly concatenated.
Note that the separator, while empty, is still present, and will show
up if you iterate this instance. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more