Skip to content

Commit

Permalink
Add the name() and name_mut() -> Option<&Name> methods to RegularType
Browse files Browse the repository at this point in the history
  • Loading branch information
Ten0 committed Jul 7, 2024
1 parent 5a21b48 commit ec86138
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions serde_avro_fast/src/schema/safe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,48 @@ pub enum RegularType {
Fixed(Fixed),
}

impl RegularType {
/// If the type is a named type, returns the name of the type.
pub fn name(&self) -> Option<&Name> {
match self {
RegularType::Record(record) => Some(&record.name),
RegularType::Enum(enum_) => Some(&enum_.name),
RegularType::Fixed(fixed) => Some(&fixed.name),
RegularType::Null
| RegularType::Boolean
| RegularType::Int
| RegularType::Long
| RegularType::Float
| RegularType::Double
| RegularType::Bytes
| RegularType::String
| RegularType::Array(_)
| RegularType::Map(_)
| RegularType::Union(_) => None,
}
}

/// If the type is a named type, returns the name of the type (mutably).
pub fn name_mut(&mut self) -> Option<&mut Name> {
match self {
RegularType::Record(record) => Some(&mut record.name),
RegularType::Enum(enum_) => Some(&mut enum_.name),
RegularType::Fixed(fixed) => Some(&mut fixed.name),
RegularType::Null
| RegularType::Boolean
| RegularType::Int
| RegularType::Long
| RegularType::Float
| RegularType::Double
| RegularType::Bytes
| RegularType::String
| RegularType::Array(_)
| RegularType::Map(_)
| RegularType::Union(_) => None,
}
}
}

/// Component of a [`SchemaMut`]
#[derive(Clone, Debug)]
pub struct Array {
Expand Down

0 comments on commit ec86138

Please sign in to comment.