Skip to content

Instantly share code, notes, and snippets.

@philippkeller
Forked from anonymous/playground.rs
Created September 13, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philippkeller/bcdd7b3ff3a2ce71104697a49a40aa8c to your computer and use it in GitHub Desktop.
Save philippkeller/bcdd7b3ff3a2ce71104697a49a40aa8c 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