Created
July 11, 2021 14:30
-
-
Save mehmetsefabalik/2f07df9bcc902d6149a80ad0ccfd5cde to your computer and use it in GitHub Desktop.
Sort Vector of Tuples in Rust
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
fn main() { | |
let mut v: Vec<(&str, i32)> = vec![("a", 2), ("b", 1), ("c", 3)]; | |
v.sort_by(|a, b| a.1.cmp(&b.1)); // increasing order | |
v.sort_by(|a, b| b.1.cmp(&a.1)); // decreasing order | |
println!("{:?}", v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @mehmetsefabalik,
How do you sort tuples vector if contents inside tuple is being changed to some option struct? For example,