How does sorting a vector of references to references of str work on the strings rather than the outermost references?
While learning rust, I ran across this snippet embedded within an answer to an online problem. I didn't expect this to be the correct answer as I naively thought elem_refs.sort() would sort by the references in the vector rather than the strings. Why does elem_refs.sort() sort on the strings rather the the references to the strings (or rather &str's) ? Obviously, it is convenient and the desired result but where is this behavior documented? Much obliged for your insights. fn main() { let list = ["b", "d" , "q", "a", "t" ]; let mut elem_refs: Vec<&&str> = list.iter().collect(); println!("{:?}",
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.