From d7716b095c2ac717245a56b331b65f25c5f22111 Mon Sep 17 00:00:00 2001 From: JoJoJet Date: Sun, 7 Aug 2022 03:04:29 -0400 Subject: [PATCH] simplify intener APIs --- crates/bevy_ecs/src/schedule/label.rs | 25 ++++--------------------- crates/bevy_macro_utils/src/lib.rs | 5 ++--- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/label.rs b/crates/bevy_ecs/src/schedule/label.rs index 3e2df89e02d2e1..f1e5a7ee438754 100644 --- a/crates/bevy_ecs/src/schedule/label.rs +++ b/crates/bevy_ecs/src/schedule/label.rs @@ -45,9 +45,10 @@ macro_rules! impl_string_label { $crate::schedule::STR_INTERN.intern(self) } fn fmt(idx: u64, f: &mut std::fmt::Formatter) -> std::fmt::Result { - $crate::schedule::STR_INTERN - .scope(idx, |s: &Self| write!(f, "{s}")) - .ok_or(::std::fmt::Error)? + let s = $crate::schedule::STR_INTERN + .get(idx) + .ok_or(std::fmt::Error)?; + write!(f, "{s}") } } }; @@ -97,14 +98,6 @@ impl TypedLabels { idx as u64 } - /// Allows one to peek at an interned label and execute code, - /// optionally returning a value. - /// - /// Returns `None` if there is no interned label with that key. - pub fn scope(&self, idx: u64, f: impl FnOnce(&T) -> U) -> Option { - self.0.read().get_index(idx as usize).map(f) - } - /// Gets a reference to the label with specified index. pub fn get(&self, idx: u64) -> Option> { RwLockReadGuard::try_map(self.0.read(), |set| set.get_index(idx as usize)).ok() @@ -191,16 +184,6 @@ impl Labels { } } - /// Allows one to peek at an interned label and execute code, - /// optionally returning a value. - /// - /// Returns `None` if there is no interned label with that key. - pub fn scope(&self, key: u64, f: impl FnOnce(&L) -> U) -> Option { - let type_map = self.0.read(); - let set = type_map.get::>()?; - set.get_index(key as usize).map(f) - } - /// Gets a reference to the label with specified index. pub fn get(&self, key: u64) -> Option> { RwLockReadGuard::try_map(self.0.read(), |type_map| { diff --git a/crates/bevy_macro_utils/src/lib.rs b/crates/bevy_macro_utils/src/lib.rs index 61084ddbffb9b8..390a3be7573b09 100644 --- a/crates/bevy_macro_utils/src/lib.rs +++ b/crates/bevy_macro_utils/src/lib.rs @@ -412,9 +412,8 @@ fn derive_interned_label( #interner_ident .intern(self) } fn fmt(idx: u64, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - #interner_ident - .scope(idx, |val: &Self| ::std::fmt::Debug::fmt(val, f)) - .ok_or(::std::fmt::Error)? + let val: #guard_type_path = #interner_ident .get(idx).ok_or(::std::fmt::Error)?; + ::std::fmt::Debug::fmt(&*val, f) } }