Created
October 26, 2017 19:19
-
-
Save gabrfarina/90ad75327362e47d7660f2fc6c25cd8a to your computer and use it in GitHub Desktop.
sorted.rs
This file contains hidden or 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
trait Sorted { | |
fn sorted(mut self) -> Self; | |
} | |
impl<T> Sorted for Vec<T> where T: Ord { | |
fn sorted(mut self) -> Self { | |
self.sort(); | |
self | |
} | |
} | |
fn main() { | |
let names: Vec<_> = "Escort Falcon Fiesta Mustang" | |
.split_whitespace() | |
.collect::<Vec<_>>() | |
.sorted(); | |
for name in names { | |
println!("Ford {}", name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment