-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Assorted small small style refactors #16205
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
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Can you justify why these changes are good? One sentence is fine. |
@@ -95,8 +95,7 @@ impl RelativeCursorPosition { | |||
/// A helper function to check if the mouse is over the node | |||
pub fn mouse_over(&self) -> bool { | |||
self.normalized | |||
.map(|position| self.normalized_visible_node_rect.contains(position)) | |||
.unwrap_or(false) | |||
.map_or(false, |position| self.normalized_visible_node_rect.contains(position)) |
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.
there's some distaste amongst some contributors (me included) with using map_or
as it's harder to read because it put the "or" case first
for child in children { | ||
let values = text_reader | ||
.iter(child) | ||
.map(|(_, _, text, _, _)| text.into()) | ||
.map(|(_, _, text, _, _)| text.to_string()) | ||
.collect::<Vec<String>>(); | ||
if !values.is_empty() { | ||
name = Some(values.join(" ")); | ||
name = Some(values.join(" ").into_boxed_str()); | ||
} | ||
} | ||
name.map(String::into_boxed_str) | ||
name |
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.
Your changes seem sensible, but this function doesn't look right. Even if it's correct, it could iterate children
backwards and short circuit return the first success rather than collecting and throwing away all these intermediate vecs?
Looks like this should be closed in favor of #16250 as it's a subset of the same changes. |
Objective
Solution
we can directly assign the result of the loop to name
text.into() can be changing the type conversion method to be more explicit.
Testing
Showcase
While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases:
Click to view showcase
Migration Guide