From 77de9a5bebb9576626b5abef7a98fa4a4ab2a07e Mon Sep 17 00:00:00 2001 From: andriyDev Date: Thu, 28 Mar 2024 08:53:26 -0700 Subject: [PATCH] Allow converting mutable handle borrows to AssetId. (#12759) ## Problem - A mutable borrow of a handle cannot be directly turned into an AssetId with `.into()`. You must do a reborrow `&*my_handle`. ## Solution - Add an impl for From<&mut Handle> to AssetId and UntypedAssetId. --- crates/bevy_asset/src/handle.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index 40bdac7e393b2..b2ebea2af9024 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -263,6 +263,20 @@ impl From<&Handle> for UntypedAssetId { } } +impl From<&mut Handle> for AssetId { + #[inline] + fn from(value: &mut Handle) -> Self { + value.id() + } +} + +impl From<&mut Handle> for UntypedAssetId { + #[inline] + fn from(value: &mut Handle) -> Self { + value.id().into() + } +} + /// An untyped variant of [`Handle`], which internally stores the [`Asset`] type information at runtime /// as a [`TypeId`] instead of encoding it in the compile-time type. This allows handles across [`Asset`] types /// to be stored together and compared.