Skip to content
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

Use question mark operator when possible #11865

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@ fn entity_from_path(
let mut parts = path.parts.iter().enumerate();

// check the first name is the root node which we already have
let Some((_, root_name)) = parts.next() else {
return None;
};
let (_, root_name) = parts.next()?;
if names.get(current_entity) != Ok(root_name) {
return None;
}
Expand Down
16 changes: 4 additions & 12 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,9 +1668,7 @@ impl<'w> FilteredEntityRef<'w> {
/// Returns `None` if the entity does not have a component of type `T`.
#[inline]
pub fn get<T: Component>(&self) -> Option<&'w T> {
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
return None;
};
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
self.access
.has_read(id)
// SAFETY: We have read access so we must have the component
Expand All @@ -1683,9 +1681,7 @@ impl<'w> FilteredEntityRef<'w> {
/// Returns `None` if the entity does not have a component of type `T`.
#[inline]
pub fn get_ref<T: Component>(&self) -> Option<Ref<'w, T>> {
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
return None;
};
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
self.access
.has_read(id)
// SAFETY: We have read access so we must have the component
Expand All @@ -1696,9 +1692,7 @@ impl<'w> FilteredEntityRef<'w> {
/// detection in custom runtimes.
#[inline]
pub fn get_change_ticks<T: Component>(&self) -> Option<ComponentTicks> {
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
return None;
};
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
self.access
.has_read(id)
// SAFETY: We have read access so we must have the component
Expand Down Expand Up @@ -1944,9 +1938,7 @@ impl<'w> FilteredEntityMut<'w> {
/// Returns `None` if the entity does not have a component of type `T`.
#[inline]
pub fn get_mut<T: Component>(&mut self) -> Option<Mut<'_, T>> {
let Some(id) = self.entity.world().components().get_id(TypeId::of::<T>()) else {
return None;
};
let id = self.entity.world().components().get_id(TypeId::of::<T>())?;
self.access
.has_write(id)
// SAFETY: We have write access so we must have the component
Expand Down
11 changes: 3 additions & 8 deletions crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ pub fn ui_focus_system(
return None;
};

let Some(view_visibility) = node.view_visibility else {
return None;
};
let view_visibility = node.view_visibility?;
// Nodes that are not rendered should not be interactable
if !view_visibility.get() {
// Reset their interaction to None to avoid strange stuck state
Expand All @@ -237,13 +235,10 @@ pub fn ui_focus_system(
}
return None;
}
let Some(camera_entity) = node
let camera_entity = node
.target_camera
.map(TargetCamera::entity)
.or(default_ui_camera.get())
else {
return None;
};
.or(default_ui_camera.get())?;

let node_rect = node.node.logical_rect(node.global_transform);

Expand Down