Created
September 13, 2016 20:45
-
-
Save anonymous/806a4080dba435b70e0b7b3f567fc8c3 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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