Skip to content

Add impl From<Uuid> for Handle #21349

@JMLX42

Description

@JMLX42

What problem does this solve or what need does it fill?

https://bevy.org/learn/migration-guides/0-16-to-0-17/#handle-weak-has-been-replaced-by-handle-uuid

Since 0.17, Handle::Uuid replaces Handle::Weak.

Users using the Handle::Weak variant directly should consider replacing it with AssetId instead, accessible through Handle::id. These situations are very case-by-case migrations.

But that does not work for users doing the opposite: creating a Handle from a Uuid. For example when loading assets dynamically from a server with per-resource uuid. There is no elegant solution to create the Handle::Uuid variant:

let handle = Handle::Uuid(uuid, PhantomData);
let handle = Handle::Uuid(uuid, Default::default());

What solution would you like?

let handle = Handle::from_uuid(uuid);

and/or

impl From<Uuid> for Handle {
  fn from(uuid: Uuid) -> Self {
    Handle::Uuid(uuid, PhantomData)
  }
}

What alternative(s) have you considered?

The uuid_handle!() but it works only for static const &str (str literals).

Additional context

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-FeatureA new feature, making something new possibleS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions