Kriskras99 commented on issue #400:
URL: https://github.com/apache/avro-rs/issues/400#issuecomment-3758844309
Sorry, that's my fault. `#schema_def` is something from the avro_derive
code. Here's a type expanded, so you can see what's going on:
```rust
pub struct Recursive {
field: Option<Box<Recursive>>,
}
impl AvroSchemaComponent for Recursive {
fn get_schema_in_ctxt(
named_schemas: &mut Names,
enclosing_namespace: &Option<String>,
) -> Schema {
let name = Name::new("Recursive")
.expect("Unable to parse schema name Recursive")
.fully_qualified_name(enclosing_namespace);
if named_schemas.contains_key(&name) {
Schema::Ref { name }
} else {
let enclosing_namespace = &name.namespace;
// Without this, this function would recurse forever and cause a
stackoverflow
named_schemas.insert(name.clone(), Schema::Ref { name:
name.clone() });
let schema = {
let schema_fields = vec![
RecordField::builder()
.name("field".to_string())
// This is the recursive call
.schema(<Option<Box<Recursive>>>::get_schema_in_ctxt(
named_schemas,
enclosing_namespace,
))
.build(),
];
Schema::Record(
RecordSchema::builder()
.name(name.clone())
.lookup(
schema_fields
.iter()
.map(|field| (field.name.clone(),
field.position))
.collect(),
)
.fields(schema_fields)
.build(),
)
};
named_schemas.insert(name, schema.clone());
schema
}
}
}
```
Note: it does not matter what is inserted into `named_schemas` the first
time, instead of a `Schema::Ref` it could also be a `Schema::Null`. The reason
that I insert a `Schema::Ref`, is that user implementations of
`AvroSchemaComponent` may depend on the type that is in `named_schemas`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]