Skip to content

Commit 67cc605

Browse files
authored
Removed Into<AssedId<T>> for Handle<T> as mentioned in #12600 (#12655)
Fixes #12600 ## Solution Removed Into<AssetId<T>> for Handle<T> as proposed in Issue conversation, fixed dependent code ## Migration guide If you use passing Handle by value as AssetId, you should pass reference or call .id() method on it Before (0.13): `assets.insert(handle, value);` After (0.14): `assets.insert(&handle, value);` or `assets.insert(handle.id(), value);`
1 parent b09f3bd commit 67cc605

File tree

9 files changed

+11
-32
lines changed

9 files changed

+11
-32
lines changed

crates/bevy_asset/src/handle.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -249,27 +249,13 @@ impl<A: Asset> PartialEq for Handle<A> {
249249

250250
impl<A: Asset> Eq for Handle<A> {}
251251

252-
impl<A: Asset> From<Handle<A>> for AssetId<A> {
253-
#[inline]
254-
fn from(value: Handle<A>) -> Self {
255-
value.id()
256-
}
257-
}
258-
259252
impl<A: Asset> From<&Handle<A>> for AssetId<A> {
260253
#[inline]
261254
fn from(value: &Handle<A>) -> Self {
262255
value.id()
263256
}
264257
}
265258

266-
impl<A: Asset> From<Handle<A>> for UntypedAssetId {
267-
#[inline]
268-
fn from(value: Handle<A>) -> Self {
269-
value.id().into()
270-
}
271-
}
272-
273259
impl<A: Asset> From<&Handle<A>> for UntypedAssetId {
274260
#[inline]
275261
fn from(value: &Handle<A>) -> Self {
@@ -429,13 +415,6 @@ impl PartialOrd for UntypedHandle {
429415
}
430416
}
431417

432-
impl From<UntypedHandle> for UntypedAssetId {
433-
#[inline]
434-
fn from(value: UntypedHandle) -> Self {
435-
value.id()
436-
}
437-
}
438-
439418
impl From<&UntypedHandle> for UntypedAssetId {
440419
#[inline]
441420
fn from(value: &UntypedHandle) -> Self {

crates/bevy_asset/src/io/embedded/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub fn watched_path(_source_file_path: &'static str, _asset_path: &'static str)
254254
macro_rules! load_internal_asset {
255255
($app: ident, $handle: expr, $path_str: expr, $loader: expr) => {{
256256
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
257-
assets.insert($handle, ($loader)(
257+
assets.insert($handle.id(), ($loader)(
258258
include_str!($path_str),
259259
std::path::Path::new(file!())
260260
.parent()
@@ -266,7 +266,7 @@ macro_rules! load_internal_asset {
266266
// we can't support params without variadic arguments, so internal assets with additional params can't be hot-reloaded
267267
($app: ident, $handle: ident, $path_str: expr, $loader: expr $(, $param:expr)+) => {{
268268
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
269-
assets.insert($handle, ($loader)(
269+
assets.insert($handle.id(), ($loader)(
270270
include_str!($path_str),
271271
std::path::Path::new(file!())
272272
.parent()
@@ -284,7 +284,7 @@ macro_rules! load_internal_binary_asset {
284284
($app: ident, $handle: expr, $path_str: expr, $loader: expr) => {{
285285
let mut assets = $app.world.resource_mut::<$crate::Assets<_>>();
286286
assets.insert(
287-
$handle,
287+
$handle.id(),
288288
($loader)(
289289
include_bytes!($path_str).as_ref(),
290290
std::path::Path::new(file!())

crates/bevy_asset/src/reflect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<A: Asset + FromReflect> FromType<A> for ReflectAsset {
149149
let mut assets = world.resource_mut::<Assets<A>>();
150150
let value: A = FromReflect::from_reflect(value)
151151
.expect("could not call `FromReflect::from_reflect` in `ReflectAsset::set`");
152-
assets.insert(handle.typed_debug_checked(), value);
152+
assets.insert(&handle.typed_debug_checked(), value);
153153
},
154154
len: |world| {
155155
let assets = world.resource::<Assets<A>>();
@@ -161,7 +161,7 @@ impl<A: Asset + FromReflect> FromType<A> for ReflectAsset {
161161
},
162162
remove: |world, handle| {
163163
let mut assets = world.resource_mut::<Assets<A>>();
164-
let value = assets.remove(handle.typed_debug_checked());
164+
let value = assets.remove(&handle.typed_debug_checked());
165165
value.map(|value| Box::new(value) as Box<dyn Reflect>)
166166
},
167167
}

crates/bevy_pbr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl Plugin for PbrPlugin {
328328
}
329329

330330
app.world.resource_mut::<Assets<StandardMaterial>>().insert(
331-
Handle::<StandardMaterial>::default(),
331+
&Handle::<StandardMaterial>::default(),
332332
StandardMaterial {
333333
base_color: Color::srgb(1.0, 0.0, 0.5),
334334
unlit: true,

crates/bevy_render/src/texture/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Plugin for ImagePlugin {
9090
.register_asset_reflect::<Image>();
9191
app.world
9292
.resource_mut::<Assets<Image>>()
93-
.insert(Handle::default(), Image::default());
93+
.insert(&Handle::default(), Image::default());
9494
#[cfg(feature = "basis-universal")]
9595
if let Some(processor) = app
9696
.world

crates/bevy_scene/src/scene_spawner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ mod tests {
482482

483483
let scene_id = world.resource_mut::<Assets<DynamicScene>>().add(scene);
484484
let instance_id = scene_spawner
485-
.spawn_dynamic_sync(&mut world, scene_id)
485+
.spawn_dynamic_sync(&mut world, &scene_id)
486486
.unwrap();
487487

488488
// verify we spawned exactly one new entity with our expected component

crates/bevy_sprite/src/mesh2d/color_material.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Plugin for ColorMaterialPlugin {
2525
.register_asset_reflect::<ColorMaterial>();
2626

2727
app.world.resource_mut::<Assets<ColorMaterial>>().insert(
28-
Handle::<ColorMaterial>::default(),
28+
&Handle::<ColorMaterial>::default(),
2929
ColorMaterial {
3030
color: Color::srgb(1.0, 0.0, 1.0),
3131
..Default::default()

examples/2d/mesh2d_manual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl Plugin for ColoredMesh2dPlugin {
274274
// Load our custom shader
275275
let mut shaders = app.world.resource_mut::<Assets<Shader>>();
276276
shaders.insert(
277-
COLORED_MESH2D_SHADER_HANDLE,
277+
&COLORED_MESH2D_SHADER_HANDLE,
278278
Shader::from_wgsl(COLORED_MESH2D_SHADER, file!()),
279279
);
280280

examples/shader/array_texture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn create_array_texture(
5454
mut materials: ResMut<Assets<ArrayTextureMaterial>>,
5555
) {
5656
if loading_texture.is_loaded
57-
|| asset_server.load_state(loading_texture.handle.clone()) != LoadState::Loaded
57+
|| asset_server.load_state(loading_texture.handle.id()) != LoadState::Loaded
5858
{
5959
return;
6060
}

0 commit comments

Comments
 (0)