You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
674 B
41 lines
674 B
#![allow(unused_macros)]
|
|
pub trait JoinStrsExt: Sized
|
|
{
|
|
/// Join an iterator of `str` with a seperator
|
|
fn join(self, with: &str) -> String;
|
|
}
|
|
|
|
impl<T,I> JoinStrsExt for I
|
|
where I: Iterator<Item=T>,
|
|
T: AsRef<str>
|
|
{
|
|
fn join(self, with: &str) -> String
|
|
{
|
|
let mut output = String::new();
|
|
let mut first=true;
|
|
for string in self
|
|
{
|
|
if !first {
|
|
output.push_str(with);
|
|
}
|
|
let string = string.as_ref();
|
|
output.push_str(string);
|
|
first=false;
|
|
}
|
|
output
|
|
}
|
|
}
|
|
|
|
macro_rules! unwrap {
|
|
($value:expr) => {
|
|
{
|
|
match $value {
|
|
Ok(value) => value,
|
|
Err(error) => {
|
|
panic!("Fatal error: {}", error)
|
|
},
|
|
}
|
|
}
|
|
};
|
|
}
|