Struct Welder

Source
pub struct Welder<G, T> { /* private fields */ }
Expand description

An helper struct to accumalate elements.

Implementations§

Source§

impl<G, T: Default> Welder<G, T>

Source

pub fn new(glue: G) -> Self

Create an empty Welder just by defining the glue used.

§Examples
use welder::Welder;

let welder = Welder::new(' ');

let string: String = welder.weld();

assert_eq!("", &string);
Source

pub fn with_start<E>(glue: G, start: E) -> Self
where T: Extend<E>,

Create a Welder with a first value and the glue it will use.

§Examples
use welder::Welder;

let welder = Welder::with_start(' ', "foo");

let string: String = welder.weld();

assert_eq!("foo", &string);
Source§

impl<G, T> Welder<G, T>

Source

pub fn weld(self) -> T

Retrieve the accumulated values from the Welder.

§Examples
use welder::Welder;

let welder = Welder::with_start(' ', "foo");

let welder = welder.elem("bar").elem("baz").elem("foo");

let string: String = welder.weld();

assert_eq!("foo bar baz foo", &string);
Source

pub fn elem_no_glue<E>(self, elem: E) -> Self
where T: Extend<E>,

This function will add the element without any glue.

§Examples
use welder::Welder;

let welder = Welder::with_start(' ', "foo");

let welder = welder.elem_no_glue("bar");
let welder = welder.elem_no_glue("baz");

let string: String = welder.weld();
assert_eq!("foobarbaz", &string);
Source

pub fn elems_no_glue<I>(self, elems: I) -> Self
where I: IntoIterator, T: Extend<I::Item>,

This function will add each element without any glue.

§Examples
use welder::Welder;

let welder = Welder::with_start(' ', "foo");

let welder = welder.elems_no_glue(vec!["bar", "baz"]);

let string: String = welder.weld();
assert_eq!("foobarbaz", &string);
Source§

impl<G, T> Welder<G, T>
where G: Clone, T: Extend<G>,

Source

pub fn elem<E>(self, elem: E) -> Self
where T: Extend<E>,

Push a new value to the already accumulated values. This function will add a glue element in front of the element.

§Examples
use welder::Welder;

let welder = Welder::new(' ');

let welder = welder.elem("foo");
let welder = welder.elem("bar");
let welder = welder.elem("baz");

let string: String = welder.weld();
assert_eq!(" foo bar baz", &string);
Source

pub fn elems<I>(self, elems: I) -> Self
where I: IntoIterator, T: Extend<I::Item>,

Push all elements to the already accumulated values. This function will add a glue in front of each element.

§Examples
use welder::Welder;

let welder = Welder::new(' ');

let welder = welder.elems(vec!["foo", "bar", "baz"]);

let string: String = welder.weld();
assert_eq!(" foo bar baz", &string);
Source

pub fn elem_glue_right<E>(self, elem: E) -> Self
where T: Extend<E>,

It will add a glue only to right of the element.

§Examples
use welder::Welder;

let welder = Welder::with_start(' ', "foo");

let welder = welder.elem_glue_right("bar");
let welder = welder.elem_glue_right("baz");

let string: String = welder.weld();
assert_eq!("foobar baz ", &string);
Source

pub fn elems_glue_right<I>(self, elems: I) -> Self
where I: IntoIterator, T: Extend<I::Item>,

This function will add a glue to the right of each element.

§Examples
use welder::Welder;

let welder = Welder::with_start(' ', "foo");

let welder = welder.elems_glue_right(vec!["bar", "baz"]);

let string: String = welder.weld();
assert_eq!("foobar baz ", &string);
Source

pub fn elem_glue_left<E>(self, elem: E) -> Self
where T: Extend<E>,

This is the default elem function. It will add a glue only to the left of the element.

§Examples
use welder::Welder;

let welder = Welder::new(' ');

let welder = welder.elem_glue_left("foo");

let string: String = welder.weld();
assert_eq!(" foo", &string);
Source

pub fn elems_glue_left<I>(self, elems: I) -> Self
where I: IntoIterator, T: Extend<I::Item>,

Push elements to the already accumulated values. This function will add a glue in front of each element.

§Examples
use welder::Welder;

let welder = Welder::new(' ');

let welder = welder.elems(vec!["foo", "bar", "baz"]);

let string: String = welder.weld();
assert_eq!(" foo bar baz", &string);
Source

pub fn elem_glue_both<E>(self, elem: E) -> Self
where T: Extend<E>,

This function will add a glue on both sides of the element.

§Examples
use welder::Welder;

let welder = Welder::new(' ');

let welder = welder.elem_glue_both("foo");
let welder = welder.elem_glue_both("bar");

let string: String = welder.weld();
assert_eq!(" foo  bar ", &string);
Source

pub fn elems_glue_both<I>(self, elems: I) -> Self
where I: IntoIterator, T: Extend<I::Item>,

This function will add a glue on both sides of each element.

§Examples
use welder::Welder;

let welder = Welder::new(' ');

let welder = welder.elems_glue_both(vec!["foo", "bar"]);

let string: String = welder.weld();
assert_eq!(" foo  bar ", &string);

Auto Trait Implementations§

§

impl<G, T> Freeze for Welder<G, T>
where G: Freeze, T: Freeze,

§

impl<G, T> RefUnwindSafe for Welder<G, T>

§

impl<G, T> Send for Welder<G, T>
where G: Send, T: Send,

§

impl<G, T> Sync for Welder<G, T>
where G: Sync, T: Sync,

§

impl<G, T> Unpin for Welder<G, T>
where G: Unpin, T: Unpin,

§

impl<G, T> UnwindSafe for Welder<G, T>
where G: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.