Skip to content

Commit

Permalink
Update the Serde impl after serde-rs/serde#2505
Browse files Browse the repository at this point in the history
Also see serde-rs/serde#2496

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
  • Loading branch information
martin-g committed Aug 15, 2023
1 parent 43339a8 commit afa8f30
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions lang/rust/avro/src/de.rs
Expand Up @@ -515,6 +515,7 @@ impl<'a, 'de> de::Deserializer<'de> for &'a Deserializer<'de> {
match *self.input {
// This branch can be anything...
Value::Record(ref fields) => visitor.visit_enum(EnumDeserializer::new(fields)),
Value::String(ref field) => visitor.visit_enum(EnumUnitDeserializer::new(field)),
// This has to be a unit Enum
Value::Enum(_index, ref field) => visitor.visit_enum(EnumUnitDeserializer::new(field)),
_ => Err(de::Error::custom(format!(
Expand Down
6 changes: 3 additions & 3 deletions lang/rust/avro/src/ser.rs
Expand Up @@ -200,10 +200,10 @@ impl<'b> ser::Serializer for &'b mut Serializer {
fn serialize_unit_variant(
self,
_: &'static str,
index: u32,
_variant_index: u32,
variant: &'static str,
) -> Result<Self::Ok, Self::Error> {
Ok(Value::Enum(index, variant.to_string()))
Ok(Value::String(variant.to_string()))
}

fn serialize_newtype_struct<T: ?Sized>(
Expand Down Expand Up @@ -720,7 +720,7 @@ mod tests {
a: UnitExternalEnum::Val1,
};

let expected = Value::Record(vec![("a".to_owned(), Value::Enum(0, "Val1".to_owned()))]);
let expected = Value::Record(vec![("a".to_owned(), Value::String("Val1".to_owned()))]);

assert_eq!(
to_value(test)?,
Expand Down

0 comments on commit afa8f30

Please sign in to comment.