Skip to content

Commit

Permalink
Allow converting mutable handle borrows to AssetId. (#12759)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
andriyDev authored Mar 28, 2024
1 parent f924b4d commit 77de9a5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 77de9a5

Please sign in to comment.