diff --git a/ciborium/src/value/de.rs b/ciborium/src/value/de.rs index c1cc8ef..30e69ee 100644 --- a/ciborium/src/value/de.rs +++ b/ciborium/src/value/de.rs @@ -365,6 +365,7 @@ impl<'a, 'de> de::Deserializer<'de> for Deserializer<&'a Value> { match value { Value::Bytes(x) => visitor.visit_bytes(x), + Value::Array(x) => visitor.visit_seq(Deserializer(x.iter())), _ => Err(de::Error::invalid_type(value.into(), &"bytes")), } } @@ -641,3 +642,18 @@ impl Value { T::deserialize(Deserializer(self)) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserialize_bytes_from_array() { + let value = Value::serialized(&[1, 2, 3, 4]).unwrap(); + assert!(value.is_array()); + + let bytes = value.deserialized::>().unwrap(); + + assert_eq!(bytes, &[1, 2, 3, 4]); + } +}