Skip to content

Commit

Permalink
refactor: use question-mark operator
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed Feb 14, 2024
1 parent 0354ce4 commit 232c86a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
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

0 comments on commit 232c86a

Please sign in to comment.