Repository: bevyengine/bevy
File: crates/bevy_ecs/src/world/entity_access/entity_ref.rs (Rust)

Code before:
        // - The query is read-only, and read-only references cannot have conflicts.
        unsafe { self.cell.get_components::<Q>() }
    }

    /// Returns the source code location from which this entity has been spawned.
    pub fn spawned_by(&self) -> MaybeLocation {
        self.cell.spawned_by()
    }

    /// Returns the [`Tick`] at which this entity has been spawned.
    pub fn spawn_tick(&self) -> Tick {
        self.cell.spawn_tick()
    }
}

impl<'a> From<EntityRef<'a>> for FilteredEntityRef<'a, 'static> {
    #[inline]
    fn from(entity: EntityRef<'a>) -> Self {
        entity.into_filtered()
    }
}

impl<'a> From<&'a EntityRef<'_>> for FilteredEntityRef<'a, 'static> {
    #[inline]
    fn from(entity: &'a EntityRef<'_>) -> Self {
        (*entity).into_filtered()
    }
}

impl PartialEq for EntityRef<'_> {
    fn eq(&self, other: &Self) -> bool {
        self.entity() == other.entity()
    }
}

impl Eq for EntityRef<'_> {}

impl PartialOrd for EntityRef<'_> {
    /// [`EntityRef`]'s comparison trait implementations match the underlying [`Entity`],
    /// and cannot discern between different worlds.
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for EntityRef<'_> {
    fn cmp(&self, other: &Self) -> Ordering {
        self.entity().cmp(&other.entity())
    }
}


Review comment (bug):
Is the `*` here actually necessary?  

```suggestion
        entity.into_filtered()
```

... and now that I'm looking at this more closely, can the signature be loosened?  I think `&'a EntityRef<'b>` can go to `FilteredEntityRef<'b>` instead of just `'a`, since you can copy out the full `EntityRef<'b>`.  And the changes in this PR mean the compiler will catch it if I'm wrong!  

Code after:
        // - The query is read-only, and read-only references cannot have conflicts.
        unsafe { self.cell.get_components::<Q>() }
    }

    /// Returns the source code location from which this entity has been spawned.
    pub fn spawned_by(&self) -> MaybeLocation {
        self.cell.spawned_by()
    }

    /// Returns the [`Tick`] at which this entity has been spawned.
    pub fn spawn_tick(&self) -> Tick {
        self.cell.spawn_tick()
    }
}

impl<'a> From<EntityRef<'a>> for FilteredEntityRef<'a, 'static> {
    #[inline]
    fn from(entity: EntityRef<'a>) -> Self {
        entity.into_filtered()
    }
}

impl<'a> From<&EntityRef<'a>> for FilteredEntityRef<'a, 'static> {
    #[inline]
    fn from(entity: &EntityRef<'a>) -> Self {
        entity.into_filtered()
    }
}

impl PartialEq for EntityRef<'_> {
    fn eq(&self, other: &Self) -> bool {
        self.entity() == other.entity()
    }
}

impl Eq for EntityRef<'_> {}

impl PartialOrd for EntityRef<'_> {
    /// [`EntityRef`]'s comparison trait implementations match the underlying [`Entity`],
    /// and cannot discern between different worlds.
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for EntityRef<'_> {
    fn cmp(&self, other: &Self) -> Ordering {
        self.entity().cmp(&other.entity())
    }
}