joinery::join

Trait Joinable

Source
pub trait Joinable: Sized {
    type Collection;

    // Required method
    fn join_with<S>(self, sep: S) -> Join<Self::Collection, S>;

    // Provided method
    fn join_concat(self) -> Join<Self::Collection, NoSeparator> { ... }
}
Expand description

A trait for converting collections into Join instances.

This trait is implemented for all referentially iterable types; that is, for all types for which &T: IntoIterator. See join_with for an example of its usage.

Required Associated Types§

Required Methods§

Source

fn join_with<S>(self, sep: S) -> Join<Self::Collection, S>

Combine this object with a separator to create a new Join instance. Note that the separator does not have to share the same type as the iterator’s values.

§Examples
use joinery::Joinable;

let parts = vec!["this", "is", "a", "sentence"];
let join = parts.join_with(' ');
assert_eq!(join.to_string(), "this is a sentence");

Provided Methods§

Source

fn join_concat(self) -> Join<Self::Collection, NoSeparator>

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.

§Examples
use joinery::Joinable;

let parts = vec!['a', 'b', 'c', 'd', 'e'];
let join = parts.join_concat();
assert_eq!(join.to_string(), "abcde");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Joinable for T
where for<'a> &'a T: IntoIterator,