use serde::de::{SeqAccess, Visitor}; use crate::protocol::KvsRequest; pub struct KvsRequestDeleteVisitor; impl<'de, const SIZE: usize> Visitor<'de> for KvsRequestDeleteVisitor { type Value = KvsRequest; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { formatter.write_str("KvsRequest::Delete") } fn visit_seq(self, mut seq: A) -> Result where A: SeqAccess<'de>, { let key: u64 = seq.next_element()?.unwrap(); Ok(KvsRequest::Delete { key }) } fn visit_map(self, mut map: A) -> Result where A: serde::de::MapAccess<'de>, { let mut key = None; loop { let k: Option = map.next_key()?; if let Some(k) = k { match k.as_str() { "key" => { key = Some(map.next_value()?); } _ => panic!(), } } else { break; } } assert!(key.is_some()); Ok(KvsRequest::Delete { key: key.unwrap() }) } }