pub(crate) struct EnumDeserializer<'a, T: std::io::BufRead + std::io::Seek> {
pub root: &'a mut crate::Deserializer<T>,
}
impl<'d, 'a, T: std::io::BufRead + std::io::Seek> serde::de::EnumAccess<'d> for EnumDeserializer<'a, T> {
type Error = crate::DeserializeError;
type Variant = Self;
fn variant_seed<K: serde::de::DeserializeSeed<'d>>(self, seed: K) -> Result<(K::Value, Self), crate::DeserializeError> {
self.root.buf.clear();
let read = self.root.input.read_until(b':', &mut self.root.buf)?;
let colon = self.root.buf.pop();
debug_assert_eq!(colon.map(|c| c as char), Some(':'));
let line_start = self.root.buf.iter().rev().position(|c| c == &b'\n');
self.root.seek_backwards(read - line_start.unwrap_or(0))?;
let key = seed.deserialize(crate::KeyDeserializer {
root: self.root,
})?;
Ok((key, self))
}
}
impl<'d, 'a, T: std::io::BufRead + std::io::Seek> serde::de::VariantAccess<'d> for EnumDeserializer<'a, T> {
type Error = crate::DeserializeError;
fn unit_variant(self) -> Result<(), crate::DeserializeError> {
unreachable!("unit_variant")
}
fn newtype_variant_seed<S: serde::de::DeserializeSeed<'d>>(self, seed: S)
-> Result<S::Value, crate::DeserializeError>
{
seed.deserialize(self.root)
}
fn tuple_variant<V: serde::de::Visitor<'d>>(self, _len: usize, visitor: V)
-> Result<V::Value, crate::DeserializeError>
{
serde::Deserializer::deserialize_seq(self.root, visitor)
}
fn struct_variant<V: serde::de::Visitor<'d>>(
self,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, crate::DeserializeError>
{
serde::Deserializer::deserialize_map(self.root, visitor)
}
}