Repository: bevyengine/bevy
File: crates/bevy_feathers/src/cursor.rs (Rust)

Code before:
            (EntityCursor::System(system), _, Some(cursor_icon)) => *system == *cursor_icon,
            _ => false,
        }
    }
}

impl Default for EntityCursor {
    fn default() -> Self {
        EntityCursor::System(Default::default())
    }
}

/// System which updates the window cursor icon whenever the mouse hovers over an entity with
/// a [`CursorIcon`] component. If no entity is hovered, the cursor icon is set to
/// the cursor in the [`DefaultCursor`] resource.
pub(crate) fn update_cursor(
    mut commands: Commands,
    hover_map: Option<Res<HoverMap>>,
    parent_query: Query<&ChildOf>,
    cursor_query: Query<&EntityCursor, Without<Window>>,
    q_windows: Query<(Entity, Option<&CursorIcon>), With<Window>>,
    r_default_cursor: Res<DefaultCursor>,
    r_override_cursor: Res<OverrideCursor>,
) {
    let cursor = (**r_override_cursor)
        .as_ref()
        .unwrap_or_else(|| {
            hover_map
                .and_then(|hover_map| match hover_map.get(&PointerId::Mouse) {
                    Some(hover_set) => hover_set.keys().find_map(|entity| {
                        cursor_query.get(*entity).ok().or_else(|| {
                            parent_query
                                .iter_ancestors(*entity)
                                .find_map(|e| cursor_query.get(e).ok())
                        })
                    }),
                    None => None,
                })
                .unwrap_or_else(|| &r_default_cursor)
        })
        .to_cursor_icon();

    for (entity, prev_cursor) in q_windows.iter() {
        if let Some(prev_cursor) = prev_cursor
            && cursor == *prev_cursor
        {
            continue;
        }
        commands.entity(entity).insert(cursor.clone());
    }
}

Review comment (suggestion):
You should be able to write it simply as `r_override_cursor.as_ref()`  or as `r_override_cursor.0.as_ref()`.  No need to manually deref.

Code after:
            (EntityCursor::System(system), _, Some(cursor_icon)) => *system == *cursor_icon,
            _ => false,
        }
    }
}

impl Default for EntityCursor {
    fn default() -> Self {
        EntityCursor::System(Default::default())
    }
}

/// System which updates the window cursor icon whenever the mouse hovers over an entity with
/// a [`CursorIcon`] component. If no entity is hovered, the cursor icon is set to
/// the cursor in the [`DefaultCursor`] resource.
pub(crate) fn update_cursor(
    mut commands: Commands,
    hover_map: Option<Res<HoverMap>>,
    parent_query: Query<&ChildOf>,
    cursor_query: Query<&EntityCursor, Without<Window>>,
    q_windows: Query<(Entity, Option<&CursorIcon>), With<Window>>,
    r_default_cursor: Res<DefaultCursor>,
    r_override_cursor: Res<OverrideCursor>,
) {
    let cursor = r_override_cursor.0.as_ref().unwrap_or_else(|| {
        hover_map
            .and_then(|hover_map| match hover_map.get(&PointerId::Mouse) {
                Some(hover_set) => hover_set.keys().find_map(|entity| {
                    cursor_query.get(*entity).ok().or_else(|| {
                        parent_query
                            .iter_ancestors(*entity)
                            .find_map(|e| cursor_query.get(e).ok())
                    })
                }),
                None => None,
            })
            .unwrap_or(&r_default_cursor)
    });

    for (entity, prev_cursor) in q_windows.iter() {
        if let Some(prev_cursor) = prev_cursor
            && cursor.eq_cursor_icon(prev_cursor)
        {
            continue;
        }
        commands.entity(entity).insert(cursor.to_cursor_icon());
    }
}

/// Plugin that supports automatically changing the cursor based on the hovered entity.
pub struct CursorIconPlugin;