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.
This commit is contained in:
andriyDev 2024-03-28 08:53:26 -07:00 committed by GitHub
parent f924b4d9ef
commit 77de9a5beb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -263,6 +263,20 @@ impl<A: Asset> From<&Handle<A>> for UntypedAssetId {
}
}
impl<A: Asset> From<&mut Handle<A>> for AssetId<A> {
#[inline]
fn from(value: &mut Handle<A>) -> Self {
value.id()
}
}
impl<A: Asset> From<&mut Handle<A>> for UntypedAssetId {
#[inline]
fn from(value: &mut Handle<A>) -> 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.