Skip to content

Commit

Permalink
fix(schema): add variant name to GENERIC_SCHEMA_CACHE to differenti…
Browse files Browse the repository at this point in the history
…ate enum variants
  • Loading branch information
nelson137 committed Nov 20, 2024
1 parent 046a493 commit df3e274
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions framework_crates/bones_schema/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ pub fn derive_has_schema(input: TokenStream) -> TokenStream {
let schema = {
#schema_mod::registry::GENERIC_SCHEMA_CACHE
.read()
.get(&TypeId::of::<Self>())
.get(&(TypeId::of::<Self>(), #variant_schema_name))
.copied()
};
schema.unwrap_or_else(|| {
let schema = compute_schema();

#schema_mod::registry::GENERIC_SCHEMA_CACHE
.write()
.insert(TypeId::of::<Self>(), schema);
.insert((TypeId::of::<Self>(), #variant_schema_name), schema);

schema
})
Expand Down Expand Up @@ -398,15 +398,15 @@ pub fn derive_has_schema(input: TokenStream) -> TokenStream {
let schema = {
#schema_mod::registry::GENERIC_SCHEMA_CACHE
.read()
.get(&TypeId::of::<Self>())
.get(&(TypeId::of::<Self>(), stringify!(#name)))
.copied()
};
schema.unwrap_or_else(|| {
let schema = #schema_register;

#schema_mod::registry::GENERIC_SCHEMA_CACHE
.write()
.insert(TypeId::of::<Self>(), schema);
.insert((TypeId::of::<Self>(), stringify!(name)), schema);

schema
})
Expand Down
5 changes: 3 additions & 2 deletions framework_crates/bones_schema/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ pub static SCHEMA_REGISTRY: SchemaRegistry = SchemaRegistry {
};

#[doc(hidden)]
pub static GENERIC_SCHEMA_CACHE: LazyLock<RwLock<HashMap<TypeId, &'static Schema>>> =
LazyLock::new(Default::default);
pub static GENERIC_SCHEMA_CACHE: LazyLock<
RwLock<HashMap<(TypeId, &'static str), &'static Schema>>,
> = LazyLock::new(Default::default);

#[cfg(test)]
mod test {
Expand Down

0 comments on commit df3e274

Please sign in to comment.