Skip to content

Conversation

JMLX42
Copy link
Contributor

@JMLX42 JMLX42 commented Oct 5, 2025

Objective

Closes #21349

Provides an ergonomic way to create a Handle<A> from a Uuid at runtime.

Solution

Implements the From<Uuid> trait for Handle<A>, allowing users to write:

let uuid = Uuid::new_v4();
let handle: Handle<Image> = uuid.into();

Instead of the current verbose approach:

let handle = Handle::<Image>::Uuid(uuid, PhantomData);

Testing

  • Added comprehensive test from_uuid that verifies:
    • Conversion from Uuid to Handle<A> works correctly
    • The resulting handle is a UUID variant
    • The handle ID matches the input UUID
    • Both .into() and explicit From::from() work
  • All existing handle tests continue to pass
  • Clippy and formatting checks pass

Implements conversion from Uuid to Handle<A> for easier handle creation.
This provides a more ergonomic API when working with dynamic asset UUIDs.

Closes bevyengine#21349
Copy link
Contributor

github-actions bot commented Oct 5, 2025

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@hukasu
Copy link
Contributor

hukasu commented Oct 5, 2025

the only issue here is that you would only be able to pass an Uuid of the exact same version as the internal version that bevy uses, since the type [email protected] is different from the type [email protected]

i would go for imp<T: Into<u128>, A: Asset> From<T> for Handle<A> and get the uuid people to do impl From<Uuid> for u128

@hukasu hukasu added A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Release-Note Work that should be called out in the blog due to impact D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 5, 2025
Copy link
Contributor

github-actions bot commented Oct 5, 2025

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

@alice-i-cecile alice-i-cecile removed the M-Needs-Release-Note Work that should be called out in the blog due to impact label Oct 5, 2025
@alice-i-cecile alice-i-cecile added this to the 0.17.3 milestone Oct 5, 2025
@alice-i-cecile
Copy link
Member

Generally yes, but not in that particular case. Those versions are semver compatible, so cargo update will deduplicate them for you. Users shouldn't have two distinct versions of uuid in their tree.

@hukasu
Copy link
Contributor

hukasu commented Oct 5, 2025

Those versions are semver compatible

They are until they aren't, speaking from experience, some people still haven't fully grasped the meaning of patch version, not talking explicitly about uuid though

Users shouldn't have two distinct versions of uuid in their tree.

shouldn't being the key word, it will eventually happen like all the times that people get stuck trying to use a crate that uses an older version of bevy and come to ask why the component from that crate is complaining on the newer version

@alice-i-cecile
Copy link
Member

Those versions are semver compatible

They are until they aren't, speaking from experience, some people still haven't fully grasped the meaning of patch version, not talking explicitly about uuid though

Users shouldn't have two distinct versions of uuid in their tree.

shouldn't being the key word, it will eventually happen like all the times that people get stuck trying to use a crate that uses an older version of bevy and come to ask why the component from that crate is complaining on the newer version

Let's cross that bridge when we get to it? If needed, we can re-export the Uuid type.

Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, I like these kinds of From impls for enums :) I didn't need this particular one yet, but I can see it being useful while converting types around e.g. during ser/de

@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 7, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 7, 2025
Merged via the queue into bevyengine:main with commit 6239e5c Oct 7, 2025
38 checks passed
tigregalis pushed a commit to tigregalis/bevy that referenced this pull request Oct 7, 2025
## Objective

Closes bevyengine#21349

Provides an ergonomic way to create a `Handle<A>` from a `Uuid` at
runtime.

## Solution

Implements the `From<Uuid>` trait for `Handle<A>`, allowing users to
write:
```rust
let uuid = Uuid::new_v4();
let handle: Handle<Image> = uuid.into();
```

Instead of the current verbose approach:
```rust
let handle = Handle::<Image>::Uuid(uuid, PhantomData);
```

## Testing

- Added comprehensive test `from_uuid` that verifies:
  - Conversion from `Uuid` to `Handle<A>` works correctly
  - The resulting handle is a UUID variant
  - The handle ID matches the input UUID
  - Both `.into()` and explicit `From::from()` work
- All existing handle tests continue to pass
- Clippy and formatting checks pass

---------

Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: François Mockers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add impl From<Uuid> for Handle
5 participants