use std::iter::Iterator;
pub trait StrJoin {
fn join(self, join: &str) -> String;
}
impl<I, S> StrJoin for I where
S: AsRef<str>,
I: Iterator<Item=S> {
fn join(self, join: &str) -> String {
let mut s = String::new();
for f in self {
s.push_str(f.as_ref());
s.push_str(join);
}
s.pop();
s
}
}
macro_rules! add_field {
($n:ident, $f:ident, $t:ty) => (
pub fn $n<T: Into<$t>>(mut self, val: T) -> Self {
self.$f = Some(val.into());
self
}
);
}
macro_rules! from_exp {
($ft:ty, $dt:ident, $pi:ident, $ex:expr) => {
impl From<$ft> for $dt {
fn from($pi: $ft) -> $dt {
$ex
}
}
}
}
macro_rules! from {
($ft:ty, $dt:ident, $ev:ident, $pi:ident) => {
from_exp!($ft, $dt, $pi, $dt::$ev($pi));
};
($ft:ty, $dt:ident, $ev:ident) => {
from!($ft, $dt, $ev, from);
};
}