Skip to content

Commit

Permalink
Support visiting enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Dec 30, 2022
1 parent 47190f5 commit 2f480bf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{forward_to_deserialize_any, de};
use serde::{forward_to_deserialize_any, de::{self, VariantAccess}};
use std::collections::BTreeMap;
use std::error::Error;
use std::fmt;
Expand Down Expand Up @@ -289,6 +289,16 @@ impl<'de> de::Visitor<'de> for ValueVisitor {
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Value, E> {
Ok(Value::Bytes(v))
}

fn visit_enum<A: de::EnumAccess<'de>>(self, data: A) -> Result<Self::Value, A::Error> {
let mut map = BTreeMap::new();
let (key, value) = data.variant()?;
let value = value
.newtype_variant()
.unwrap_or(Value::Unit);
map.insert(key, value);
Ok(Value::Map(map))
}
}

impl<'de> de::Deserialize<'de> for Value {
Expand Down

0 comments on commit 2f480bf

Please sign in to comment.