Skip to content

Commit

Permalink
fix for &str
Browse files Browse the repository at this point in the history
  • Loading branch information
Ten0 committed Mar 10, 2024
1 parent 0348c36 commit 886ecb2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion serde_avro_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl SchemaBuilder {
idx
}

pub fn find_or_build<T: BuildSchema>(&mut self) -> SchemaKey {
pub fn find_or_build<T: BuildSchema + ?Sized>(&mut self) -> SchemaKey {
match self
.already_built_types
.entry(TypeId::of::<T::TypeLookup>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn primitives() {
test::<Bar>(
r#"{
"type": "record",
"name": "basic.Bar",
"name": "derive_schema.Bar",
"fields": [
{
"name": "a",
Expand All @@ -46,7 +46,7 @@ fn substruct() {
test::<Foo>(
r#"{
"type": "record",
"name": "basic.Foo",
"name": "derive_schema.Foo",
"fields": [
{
"name": "primitives",
Expand Down Expand Up @@ -83,7 +83,7 @@ fn complex() {
test::<Complex>(
r#"{
"type": "record",
"name": "basic.Complex",
"name": "derive_schema.Complex",
"fields": [
{
"name": "s1",
Expand Down Expand Up @@ -132,14 +132,15 @@ fn complex() {
struct Generics<'a, F> {
s1: F,
s2: &'a F,
s: &'a str,
}

#[test]
fn generics() {
test::<Generics<'_, Bar>>(
r#"{
"type": "record",
"name": "basic.Generics_be632cb05c10a877",
"name": "derive_schema.Generics_62462e653c3a8376",
"fields": [
{
"name": "s1",
Expand All @@ -161,6 +162,10 @@ fn generics() {
{
"name": "s2",
"type": "Bar"
},
{
"name": "s",
"type": "string"
}
]
}"#,
Expand Down
5 changes: 2 additions & 3 deletions serde_avro_derive_macros/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ pub(crate) fn schema_impl(input: SchemaDeriveInput) -> Result<TokenStream, Error
// 'static otherwise it won't implement `Any`, so we need to generate a
// dedicated struct for it.
let type_lookup_ident = format_ident!("{ident}TypeLookup");
let type_params: Vec<syn::Ident> = (0..generics.params.len())
.map(|i| format_ident!("T{}", i))
.collect();
let type_params: Vec<syn::Ident> =
(0..fields.len()).map(|i| format_ident!("T{}", i)).collect();
let struct_decl = syn::ItemStruct {
attrs: Default::default(),
vis: syn::Visibility::Inherited,
Expand Down

0 comments on commit 886ecb2

Please sign in to comment.