pub struct Welder<G, T> { /* private fields */ }
Expand description
An helper struct to accumalate elements.
Implementations§
Source§impl<G, T: Default> Welder<G, T>
impl<G, T: Default> Welder<G, T>
Sourcepub fn new(glue: G) -> Self
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);
Sourcepub fn with_start<E>(glue: G, start: E) -> Selfwhere
T: Extend<E>,
pub fn with_start<E>(glue: G, start: E) -> Selfwhere
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>
impl<G, T> Welder<G, T>
Sourcepub fn weld(self) -> T
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);
Sourcepub fn elem_no_glue<E>(self, elem: E) -> Selfwhere
T: Extend<E>,
pub fn elem_no_glue<E>(self, elem: E) -> Selfwhere
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);
Sourcepub fn elems_no_glue<I>(self, elems: I) -> Self
pub fn elems_no_glue<I>(self, elems: I) -> Self
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>
impl<G, T> Welder<G, T>
Sourcepub fn elem<E>(self, elem: E) -> Selfwhere
T: Extend<E>,
pub fn elem<E>(self, elem: E) -> Selfwhere
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);
Sourcepub fn elems<I>(self, elems: I) -> Self
pub fn elems<I>(self, elems: I) -> Self
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);
Sourcepub fn elem_glue_right<E>(self, elem: E) -> Selfwhere
T: Extend<E>,
pub fn elem_glue_right<E>(self, elem: E) -> Selfwhere
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);
Sourcepub fn elems_glue_right<I>(self, elems: I) -> Self
pub fn elems_glue_right<I>(self, elems: I) -> Self
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);
Sourcepub fn elem_glue_left<E>(self, elem: E) -> Selfwhere
T: Extend<E>,
pub fn elem_glue_left<E>(self, elem: E) -> Selfwhere
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);
Sourcepub fn elems_glue_left<I>(self, elems: I) -> Self
pub fn elems_glue_left<I>(self, elems: I) -> Self
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);
Sourcepub fn elem_glue_both<E>(self, elem: E) -> Selfwhere
T: Extend<E>,
pub fn elem_glue_both<E>(self, elem: E) -> Selfwhere
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);
Sourcepub fn elems_glue_both<I>(self, elems: I) -> Self
pub fn elems_glue_both<I>(self, elems: I) -> Self
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);