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] - Rename Handle::as_weak() to cast_weak() #5321

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,15 @@ impl<T: Asset> Handle<T> {
}

/// Recasts this handle as a weak handle of an Asset `U`.
pub fn as_weak<U: Asset>(&self) -> Handle<U> {
pub fn cast_weak<U: Asset>(&self) -> Handle<U> {
let id = if let HandleId::Id(_, id) = self.id {
HandleId::Id(U::TYPE_UUID, id)
} else {
self.id
};

Handle {
id: self.id,
id,
handle_type: HandleType::Weak,
marker: PhantomData,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_text/src/glyph_brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl GlyphBrush {
let section_data = sections_data[sg.section_index];
if let Some(outlined_glyph) = section_data.1.font.outline_glyph(glyph) {
let bounds = outlined_glyph.px_bounds();
let handle_font_atlas: Handle<FontAtlasSet> = section_data.0.as_weak();
let handle_font_atlas: Handle<FontAtlasSet> = section_data.0.cast_weak();
let font_atlas_set = font_atlas_set_storage
.get_or_insert_with(handle_font_atlas, FontAtlasSet::default);

Expand Down
2 changes: 1 addition & 1 deletion examples/ui/font_atlas_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn atlas_render_system(
font_atlas_sets: Res<Assets<FontAtlasSet>>,
texture_atlases: Res<Assets<TextureAtlas>>,
) {
if let Some(set) = font_atlas_sets.get(&state.handle.as_weak::<FontAtlasSet>()) {
if let Some(set) = font_atlas_sets.get(&state.handle.cast_weak::<FontAtlasSet>()) {
if let Some((_size, font_atlas)) = set.iter().next() {
let x_offset = state.atlas_count as f32;
if state.atlas_count == font_atlas.len() as u32 {
Expand Down