-
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the output order deterministic #87
Conversation
let mut mapping = filetypes | ||
.mapping | ||
.iter() | ||
.map(|(filetype, category)| (filetype, theme.get_style(category))) | ||
.map(|(filetype, style)| style.map(|style| (filetype, style))) | ||
.collect::<Result<Vec<_>>>()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Maybe add a type annotation instead of collect::<T>()
(just like below)
let mut mapping = filetypes | |
.mapping | |
.iter() | |
.map(|(filetype, category)| (filetype, theme.get_style(category))) | |
.map(|(filetype, style)| style.map(|style| (filetype, style))) | |
.collect::<Result<Vec<_>>>()?; | |
let mut mapping: Result<Vec<_>> = filetypes | |
.mapping | |
.iter() | |
.map(|(filetype, category)| (filetype, theme.get_style(category))) | |
.map(|(filetype, style)| style.map(|style| (filetype, style))) | |
.collect()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be mapping: Vec<_> = ...collect()?;
. But rustc's type inference doesn't actually handle that. I could do
let mut mapping: Vec<_> = ...collect::<Result<_>>()?;
but I figured I might as well put everything in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! If I understand correctly, the problem was that entries were previously just sorted by a single key? Now we sort by FileType
in addition, which makes the sort order completely deterministic?
… and the rest is just a refactoring.
Yeah the functional change is just -filetypes_list.sort_unstable_by_key(|entry| entry.len());
+filetypes_list.sort_unstable_by_key(|entry| (entry.len(), entry)); Everything else is just refactoring. |
Fixes #63.