-
-
Save philippkeller/bcdd7b3ff3a2ce71104697a49a40aa8c 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