Hi,
I feel this is a bit too complicated for me so i would need some help here. What I have is a vec of structs such that one element is a string and i would like to sort my vec of structs so that the pattern within a string is utilized in sorting: Example:
use regex::Regex;
#[derive(Debug)]
struct A {
x: String,
y: usize
}
fn main() {
let vec : Vec<A> = vec![
A{x:"a2:33-7".to_string(), y:5},
A{x:"a1:23-75".to_string(), y:7},
A{x:"a10:233-76".to_string(), y:8},
A{x:"a1:3-77".to_string(), y:9},
A{x:"b2:3-78".to_string(), y:0},
A{x:"c2:263-79".to_string(), y:3},
A{x:"a34:264-79".to_string(), y:4}
];
println!("{:?}", vec);
// i need to sort A's by x s.t. the
// structs are first sorted by substring
// up to the first ':' and then int that follows
// up to '-'
// expected result:
//vec![
// A{x:"a1:3-77".to_string(), y:9},
// A{x:"a1:23-75".to_string(), y:7},
// A{x:"a2:33-7".to_string(), y:5},
// A{x:"a10:233-76".to_string(), y:8},
// A{x:"a34:264-79".to_string(), y:4},
// A{x:"b2:3-78".to_string(), y:0},
// A{x:"c2:263-79".to_string(), y:3},
//]
}
I understand that i should utilize sort_by()
but i am getting lost in parsing the String patterns when it comes to double sorting.
Thank you for all the advice you can provide!