Use question mark operator when possible (#11865)
# Objective
- There are multiple instances of `let Some(x) = ... else { None };`
throughout the project.
- Because `Option<T>` implements
[`Try`](https://doc.rust-lang.org/stable/std/ops/trait.Try.html), it can
use the question mark `?` operator.
## Solution
- Use question mark operator instead of `let Some(x) = ... else { None
}`.
---
There was another PR that did a similar thing a few weeks ago, but I
couldn't find it.
This commit is contained in:
parent
b446374392
commit
8018d62e41
@ -493,9 +493,7 @@ fn entity_from_path(
|
|||||||
let mut parts = path.parts.iter().enumerate();
|
let mut parts = path.parts.iter().enumerate();
|
||||||
|
|
||||||
// check the first name is the root node which we already have
|
// check the first name is the root node which we already have
|
||||||
let Some((_, root_name)) = parts.next() else {
|
let (_, root_name) = parts.next()?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
if names.get(current_entity) != Ok(root_name) {
|
if names.get(current_entity) != Ok(root_name) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1668,9 +1668,7 @@ impl<'w> FilteredEntityRef<'w> {
|
|||||||
/// Returns `None` if the entity does not have a component of type `T`.
|
/// Returns `None` if the entity does not have a component of type `T`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get<T: Component>(&self) -> Option<&'w T> {
|
pub fn get<T: Component>(&self) -> Option<&'w T> {
|
||||||
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
|
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
self.access
|
self.access
|
||||||
.has_read(id)
|
.has_read(id)
|
||||||
// SAFETY: We have read access so we must have the component
|
// SAFETY: We have read access so we must have the component
|
||||||
@ -1683,9 +1681,7 @@ impl<'w> FilteredEntityRef<'w> {
|
|||||||
/// Returns `None` if the entity does not have a component of type `T`.
|
/// Returns `None` if the entity does not have a component of type `T`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_ref<T: Component>(&self) -> Option<Ref<'w, T>> {
|
pub fn get_ref<T: Component>(&self) -> Option<Ref<'w, T>> {
|
||||||
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
|
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
self.access
|
self.access
|
||||||
.has_read(id)
|
.has_read(id)
|
||||||
// SAFETY: We have read access so we must have the component
|
// SAFETY: We have read access so we must have the component
|
||||||
@ -1696,9 +1692,7 @@ impl<'w> FilteredEntityRef<'w> {
|
|||||||
/// detection in custom runtimes.
|
/// detection in custom runtimes.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_change_ticks<T: Component>(&self) -> Option<ComponentTicks> {
|
pub fn get_change_ticks<T: Component>(&self) -> Option<ComponentTicks> {
|
||||||
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
|
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
self.access
|
self.access
|
||||||
.has_read(id)
|
.has_read(id)
|
||||||
// SAFETY: We have read access so we must have the component
|
// SAFETY: We have read access so we must have the component
|
||||||
@ -1944,9 +1938,7 @@ impl<'w> FilteredEntityMut<'w> {
|
|||||||
/// Returns `None` if the entity does not have a component of type `T`.
|
/// Returns `None` if the entity does not have a component of type `T`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_mut<T: Component>(&mut self) -> Option<Mut<'_, T>> {
|
pub fn get_mut<T: Component>(&mut self) -> Option<Mut<'_, T>> {
|
||||||
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
|
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
self.access
|
self.access
|
||||||
.has_write(id)
|
.has_write(id)
|
||||||
// SAFETY: We have write access so we must have the component
|
// SAFETY: We have write access so we must have the component
|
||||||
|
|||||||
@ -225,9 +225,7 @@ pub fn ui_focus_system(
|
|||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(view_visibility) = node.view_visibility else {
|
let view_visibility = node.view_visibility?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
// Nodes that are not rendered should not be interactable
|
// Nodes that are not rendered should not be interactable
|
||||||
if !view_visibility.get() {
|
if !view_visibility.get() {
|
||||||
// Reset their interaction to None to avoid strange stuck state
|
// Reset their interaction to None to avoid strange stuck state
|
||||||
@ -237,13 +235,10 @@ pub fn ui_focus_system(
|
|||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let Some(camera_entity) = node
|
let camera_entity = node
|
||||||
.target_camera
|
.target_camera
|
||||||
.map(TargetCamera::entity)
|
.map(TargetCamera::entity)
|
||||||
.or(default_ui_camera.get())
|
.or(default_ui_camera.get())?;
|
||||||
else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
let node_rect = node.node.logical_rect(node.global_transform);
|
let node_rect = node.node.logical_rect(node.global_transform);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user