Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/serde_json/tests/regression/issue795.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / serde_json / tests / regression / issue795.rs` 62 lines ยท 1646 bytes Raw Blame History 1 #![allow(clippy::assertions_on_result_states)] 2 3 use serde::de::{ 4 Deserialize, Deserializer, EnumAccess, IgnoredAny, MapAccess, VariantAccess, Visitor, 5 }; 6 use serde_json::json; 7 use std::fmt; 8 9 #[derive(Debug)] 10 pub enum Enum { 11 Variant { 12 #[allow(dead_code)] 13 x: u8, 14 }, 15 } 16 17 impl<'de> Deserialize<'de> for Enum { 18 fn deserialize(deserializer: D) -> Result 19 where 20 D: Deserializer<'de>, 21 { 22 struct EnumVisitor; 23 24 impl<'de> Visitor<'de> for EnumVisitor { 25 type Value = Enum; 26 27 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { 28 formatter.write_str("enum Enum") 29 } 30 31 fn visit_enum(self, data: A) -> Result 32 where 33 A: EnumAccess<'de>, 34 { 35 let (IgnoredAny, variant) = data.variant()?; 36 variant.struct_variant(&["x"], self) 37 } 38 39 fn visit_map(self, mut data: A) -> Result 40 where 41 A: MapAccess<'de>, 42 { 43 let mut x = 0; 44 if let Some((IgnoredAny, value)) = data.next_entry()? { 45 x = value; 46 } 47 Ok(Enum::Variant { x }) 48 } 49 } 50 51 deserializer.deserialize_enum("Enum", &["Variant"], EnumVisitor) 52 } 53 } 54 55 #[test] 56 fn test() { 57 let s = r#" {"Variant":{"x":0,"y":0}} "#; 58 assert!(serde_json::from_str::(s).is_err()); 59 60 let j = json!({"Variant":{"x":0,"y":0}}); 61 assert!(serde_json::from_value::(j).is_err()); 62 }