Replace map
+ unwrap_or(true)
with is_none_or
(#17070)
# Objective Reduce all varieties of `my_maybe.map(|x| x.is_true).unwrap_or(true)` using `is_none_or`.
This commit is contained in:
parent
d502796a41
commit
c73daea341
@ -233,8 +233,7 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> {
|
|||||||
/// Returns `true` if there are no events available to read.
|
/// Returns `true` if there are no events available to read.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.events()
|
self.events()
|
||||||
.map(|events| self.reader.is_empty(events))
|
.is_none_or(|events| self.reader.is_empty(events))
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes all available events.
|
/// Consumes all available events.
|
||||||
|
@ -139,10 +139,10 @@ impl<'w, 's, D: QueryData, F: QueryFilter> HierarchyQueryExt<'w, 's, D, F> for Q
|
|||||||
{
|
{
|
||||||
self.iter_descendants_depth_first(entity).filter(|entity| {
|
self.iter_descendants_depth_first(entity).filter(|entity| {
|
||||||
self.get(*entity)
|
self.get(*entity)
|
||||||
|
.ok()
|
||||||
// These are leaf nodes if they have the `Children` component but it's empty
|
// These are leaf nodes if they have the `Children` component but it's empty
|
||||||
.map(|children| children.is_empty())
|
|
||||||
// Or if they don't have the `Children` component at all
|
// Or if they don't have the `Children` component at all
|
||||||
.unwrap_or(true)
|
.is_none_or(|children| children.is_empty())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,10 +99,7 @@ pub fn update_hits(
|
|||||||
let entity_layers = layers.get(entity).cloned().unwrap_or_default();
|
let entity_layers = layers.get(entity).cloned().unwrap_or_default();
|
||||||
let render_layers_match = cam_layers.intersects(&entity_layers);
|
let render_layers_match = cam_layers.intersects(&entity_layers);
|
||||||
|
|
||||||
let is_pickable = pickables
|
let is_pickable = pickables.get(entity).ok().is_none_or(|p| p.is_hoverable);
|
||||||
.get(entity)
|
|
||||||
.map(|p| p.is_hoverable)
|
|
||||||
.unwrap_or(true);
|
|
||||||
|
|
||||||
marker_requirement && render_layers_match && is_pickable
|
marker_requirement && render_layers_match && is_pickable
|
||||||
},
|
},
|
||||||
|
@ -89,10 +89,7 @@ pub(crate) struct FromReflectAttrs {
|
|||||||
impl FromReflectAttrs {
|
impl FromReflectAttrs {
|
||||||
/// Returns true if `FromReflect` should be automatically derived as part of the `Reflect` derive.
|
/// Returns true if `FromReflect` should be automatically derived as part of the `Reflect` derive.
|
||||||
pub fn should_auto_derive(&self) -> bool {
|
pub fn should_auto_derive(&self) -> bool {
|
||||||
self.auto_derive
|
self.auto_derive.as_ref().is_none_or(LitBool::value)
|
||||||
.as_ref()
|
|
||||||
.map(LitBool::value)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,10 +109,7 @@ pub(crate) struct TypePathAttrs {
|
|||||||
impl TypePathAttrs {
|
impl TypePathAttrs {
|
||||||
/// Returns true if `TypePath` should be automatically derived as part of the `Reflect` derive.
|
/// Returns true if `TypePath` should be automatically derived as part of the `Reflect` derive.
|
||||||
pub fn should_auto_derive(&self) -> bool {
|
pub fn should_auto_derive(&self) -> bool {
|
||||||
self.auto_derive
|
self.auto_derive.as_ref().is_none_or(LitBool::value)
|
||||||
.as_ref()
|
|
||||||
.map(LitBool::value)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,12 +375,12 @@ impl SceneSpawner {
|
|||||||
// the scene parent
|
// the scene parent
|
||||||
if !world
|
if !world
|
||||||
.get_entity(entity)
|
.get_entity(entity)
|
||||||
|
.ok()
|
||||||
// This will filter only the scene root entity, as all other from the
|
// This will filter only the scene root entity, as all other from the
|
||||||
// scene have a parent
|
// scene have a parent
|
||||||
.map(|entity| entity.contains::<Parent>())
|
// Entities that wouldn't exist anymore are also skipped
|
||||||
// Default is true so that it won't run on an entity that wouldn't exist anymore
|
|
||||||
// this case shouldn't happen anyway
|
// this case shouldn't happen anyway
|
||||||
.unwrap_or(true)
|
.is_none_or(|entity| entity.contains::<Parent>())
|
||||||
{
|
{
|
||||||
world.entity_mut(parent).add_child(entity);
|
world.entity_mut(parent).add_child(entity);
|
||||||
}
|
}
|
||||||
|
@ -186,9 +186,7 @@ fn sprite_picking(
|
|||||||
};
|
};
|
||||||
|
|
||||||
blocked = cursor_in_valid_pixels_of_sprite
|
blocked = cursor_in_valid_pixels_of_sprite
|
||||||
&& picking_behavior
|
&& picking_behavior.is_none_or(|p| p.should_block_lower);
|
||||||
.map(|p| p.should_block_lower)
|
|
||||||
.unwrap_or(true);
|
|
||||||
|
|
||||||
cursor_in_valid_pixels_of_sprite.then(|| {
|
cursor_in_valid_pixels_of_sprite.then(|| {
|
||||||
let hit_pos_world =
|
let hit_pos_world =
|
||||||
|
@ -702,14 +702,9 @@ pub fn extract_text_sections(
|
|||||||
rect,
|
rect,
|
||||||
});
|
});
|
||||||
|
|
||||||
if text_layout_info
|
if text_layout_info.glyphs.get(i + 1).is_none_or(|info| {
|
||||||
.glyphs
|
info.span_index != current_span || info.atlas_info.texture != atlas_info.texture
|
||||||
.get(i + 1)
|
}) {
|
||||||
.map(|info| {
|
|
||||||
info.span_index != current_span || info.atlas_info.texture != atlas_info.texture
|
|
||||||
})
|
|
||||||
.unwrap_or(true)
|
|
||||||
{
|
|
||||||
let id = commands.spawn(TemporaryRenderEntity).id();
|
let id = commands.spawn(TemporaryRenderEntity).id();
|
||||||
|
|
||||||
extracted_uinodes.uinodes.insert(
|
extracted_uinodes.uinodes.insert(
|
||||||
|
Loading…
Reference in New Issue
Block a user