From df3e274c6d68e3f08ced7ae112ce2dc93f8dce52 Mon Sep 17 00:00:00 2001 From: Nelson Earle Date: Tue, 19 Nov 2024 20:47:29 -0600 Subject: [PATCH] fix(schema): add variant name to `GENERIC_SCHEMA_CACHE` to differentiate enum variants --- framework_crates/bones_schema/macros/src/lib.rs | 8 ++++---- framework_crates/bones_schema/src/registry.rs | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/framework_crates/bones_schema/macros/src/lib.rs b/framework_crates/bones_schema/macros/src/lib.rs index 7c368ccf99..0929a32ebe 100644 --- a/framework_crates/bones_schema/macros/src/lib.rs +++ b/framework_crates/bones_schema/macros/src/lib.rs @@ -285,7 +285,7 @@ pub fn derive_has_schema(input: TokenStream) -> TokenStream { let schema = { #schema_mod::registry::GENERIC_SCHEMA_CACHE .read() - .get(&TypeId::of::()) + .get(&(TypeId::of::(), #variant_schema_name)) .copied() }; schema.unwrap_or_else(|| { @@ -293,7 +293,7 @@ pub fn derive_has_schema(input: TokenStream) -> TokenStream { #schema_mod::registry::GENERIC_SCHEMA_CACHE .write() - .insert(TypeId::of::(), schema); + .insert((TypeId::of::(), #variant_schema_name), schema); schema }) @@ -398,7 +398,7 @@ pub fn derive_has_schema(input: TokenStream) -> TokenStream { let schema = { #schema_mod::registry::GENERIC_SCHEMA_CACHE .read() - .get(&TypeId::of::()) + .get(&(TypeId::of::(), stringify!(#name))) .copied() }; schema.unwrap_or_else(|| { @@ -406,7 +406,7 @@ pub fn derive_has_schema(input: TokenStream) -> TokenStream { #schema_mod::registry::GENERIC_SCHEMA_CACHE .write() - .insert(TypeId::of::(), schema); + .insert((TypeId::of::(), stringify!(name)), schema); schema }) diff --git a/framework_crates/bones_schema/src/registry.rs b/framework_crates/bones_schema/src/registry.rs index ab7c2f6f72..da589d79e7 100644 --- a/framework_crates/bones_schema/src/registry.rs +++ b/framework_crates/bones_schema/src/registry.rs @@ -149,8 +149,9 @@ pub static SCHEMA_REGISTRY: SchemaRegistry = SchemaRegistry { }; #[doc(hidden)] -pub static GENERIC_SCHEMA_CACHE: LazyLock>> = - LazyLock::new(Default::default); +pub static GENERIC_SCHEMA_CACHE: LazyLock< + RwLock>, +> = LazyLock::new(Default::default); #[cfg(test)] mod test {