Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - make Handle::<T> field id private, and replace with a getter #6176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/assets.rs
Expand Up @@ -33,21 +33,21 @@ impl<T: Asset> Debug for AssetEvent<T> {
"AssetEvent<{}>::Created",
std::any::type_name::<T>()
))
.field("handle", &handle.id)
.field("handle", &handle.id())
.finish(),
AssetEvent::Modified { handle } => f
.debug_struct(&format!(
"AssetEvent<{}>::Modified",
std::any::type_name::<T>()
))
.field("handle", &handle.id)
.field("handle", &handle.id())
.finish(),
AssetEvent::Removed { handle } => f
.debug_struct(&format!(
"AssetEvent<{}>::Removed",
std::any::type_name::<T>()
))
.field("handle", &handle.id)
.field("handle", &handle.id())
.finish(),
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/bevy_asset/src/handle.rs
Expand Up @@ -105,8 +105,7 @@ pub struct Handle<T>
where
T: Asset,
{
/// The ID of the asset as contained within its respective [`Assets`] collection
pub id: HandleId,
id: HandleId,
#[reflect(ignore)]
handle_type: HandleType,
#[reflect(ignore)]
Expand Down Expand Up @@ -151,6 +150,12 @@ impl<T: Asset> Handle<T> {
}
}

/// The ID of the asset as contained within its respective [`Assets`] collection.
#[inline]
pub fn id(&self) -> HandleId {
self.id
}

/// Recasts this handle as a weak handle of an Asset `U`.
pub fn as_weak<U: Asset>(&self) -> Handle<U> {
Handle {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_sprite/src/render/mod.rs
Expand Up @@ -261,7 +261,7 @@ pub fn extract_sprites(
custom_size: sprite.custom_size,
flip_x: sprite.flip_x,
flip_y: sprite.flip_y,
image_handle_id: handle.id,
image_handle_id: handle.id(),
anchor: sprite.anchor.as_vec(),
});
}
Expand All @@ -281,7 +281,7 @@ pub fn extract_sprites(
custom_size: atlas_sprite.custom_size,
flip_x: atlas_sprite.flip_x,
flip_y: atlas_sprite.flip_y,
image_handle_id: texture_atlas.texture.id,
image_handle_id: texture_atlas.texture.id(),
anchor: atlas_sprite.anchor.as_vec(),
});
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_text/src/pipeline.rs
Expand Up @@ -34,7 +34,7 @@ impl TextPipeline {
let brush = &mut self.brush;
*self
.map_font_id
.entry(handle.id)
.entry(handle.id())
.or_insert_with(|| brush.add_font(handle.clone(), font.font.clone()))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_text/src/text2d.rs
Expand Up @@ -134,7 +134,7 @@ pub fn extract_text2d_sprite(
color,
rect,
custom_size: None,
image_handle_id: handle.id,
image_handle_id: handle.id(),
flip_x: false,
flip_y: false,
anchor: Anchor::Center.as_vec(),
Expand Down