Skip to content

fix!: Small things - #486

Merged
martin-g merged 8 commits into
mainfrom
fix/small_things
Feb 26, 2026
Merged

martin-g merged 8 commits into
mainfrom
fix/small_things

Conversation

@Kriskras99

Copy link
Copy Markdown
Contributor

These are a bunch of small fixes that don't really deserve their own PRs.

  • fix: Use #[track_caller] for assert{,_not}_logged to show the caller source location when panicking
  • fix: Use Write::write_all in utils::encode_variable
  • fix: Change default of SER_BYTES_TYPE to BytesType::Unset and set if for every serialize/deserialize call
    • This is not used yet, but will be used in the improvements to SchemaAwareWriteSerializer that will also add enum support
  • fix: Implement AvroSchemaComponent for ()
  • fix!: Alias::name and Alias::namespace should return references, user can clone if needed
    • This is a breaking change, but easy to resolve by calling .clone() on the return value of the functions
  • fix: deserialize_big_decimal doesn't need a Vec<u8>
    • This is not used yet, but will also be used in the improvements to SchemaAwareWriteSerializer

Comment thread avro/src/serde/with.rs Resolved
@martin-g
martin-g merged commit d7f2ead into main Feb 26, 2026
21 checks passed
@martin-g
martin-g deleted the fix/small_things branch February 26, 2026 09:21
@martin-g

Copy link
Copy Markdown
Member
  • fix: Implement AvroSchemaComponent for ()

One note: Option<()> will try to generate a Union of [Null, Null] and crash due to the duplicate.
Can we make it a build error ?

@Kriskras99

Copy link
Copy Markdown
Contributor Author

We could change the implementation for option to this this:

impl<T> AvroSchemaComponent for Option<T>
where
    T: AvroSchemaComponent,
{
    fn get_schema_in_ctxt(
        named_schemas: &mut HashSet<Name>,
        enclosing_namespace: &Namespace,
    ) -> Schema {
        let schema = T::get_schema_in_ctxt(named_schemas, enclosing_namespace);
        if let Schema::Null = schema {
            Schema::Union(UnionSchema::new(vec![Schema::Null]).expect("This is a valid schema"))
        } else {
            let variants = vec![
                Schema::Null,
                schema,
            ];

            Schema::Union(
                UnionSchema::new(variants).expect("Option<T> must produce a valid (non-nested) union"),
            )
        }
    }

Then there is no error needed

@martin-g

Copy link
Copy Markdown
Member

Yep! This is also good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants