Skip to content

Instantly share code, notes, and snippets.

@gabrfarina
Created October 26, 2017 19:19
Show Gist options
  • Save gabrfarina/90ad75327362e47d7660f2fc6c25cd8a to your computer and use it in GitHub Desktop.
Save gabrfarina/90ad75327362e47d7660f2fc6c25cd8a to your computer and use it in GitHub Desktop.
sorted.rs
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