Skip to content

Instantly share code, notes, and snippets.

Created September 13, 2016 20:45
Show Gist options
  • Save anonymous/806a4080dba435b70e0b7b3f567fc8c3 to your computer and use it in GitHub Desktop.
Save anonymous/806a4080dba435b70e0b7b3f567fc8c3 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
use std::fmt;
pub trait Join {
fn join(&self) -> String;
}
impl<T: fmt::Display> Join for [T] {
fn join(&self) -> String {
self.iter()
.map(|a| format!("{}", a))
.collect::<Vec<_>>()
.concat()
}
}
fn main() {
let a = [1,2,3];
println!("{}", &a.join());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment