Kriskras99 commented on code in PR #397:
URL: https://github.com/apache/avro-rs/pull/397#discussion_r2681998438
##########
avro_derive/src/attributes/avro.rs:
##########
@@ -137,6 +154,16 @@ pub struct FieldAttributes {
/// [`serde::FieldAttributes::flatten`]:
crate::attributes::serde::FieldAttributes::flatten
#[darling(default)]
pub flatten: bool,
+ /// How to get the schema for this field.
+ ///
+ /// By default uses `<T as AvroSchemaComponent>::get_schema_in_ctxt`.
+ ///
+ /// When it's provided without an argument (`#[avro(with)]`), it will use
the function `get_schema_in_ctxt` defined
+ /// in the same module as the `#[serde(with = "..")]` attribute.
Review Comment:
That's correct!
This allows a user to define their overrides for a type in one module,
without having to give the path twice:
```rust
#[derive(AvroSchema, Serialize, Deserialize)]
struct Foo {
#[avro(with)]
#[serde(with = "bar")]
field: String,
}
mod bar {
pub fn serialize<S>(&String, S) -> Result<S::Ok, S::Error> where S:
Serializer {
todo!()
}
pub fn deserialize<'de, D>(D) -> Result<String, D::Error> where D:
Deserializer<'de> {
todo!()
}
pub fn get_schema_in_ctxt(named_schemas: &mut Names,
enclosing_namespace: &Namespace) -> Schema {
todo!()
}
}
```
--
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]