(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V,
)
| 109 | } |
| 110 | |
| 111 | fn deserialize_enum<V: Visitor<'de>>( |
| 112 | self, |
| 113 | _name: &'static str, |
| 114 | _variants: &'static [&'static str], |
| 115 | visitor: V, |
| 116 | ) -> Result<V::Value, Self::Error> { |
| 117 | let token = self.scan()?; |
| 118 | let token_range = Range::new(self.scanner.token_start(), self.scanner.token_end()); |
| 119 | let text = self.text; |
| 120 | let result = match token { |
| 121 | Some(Token::String(s)) => { |
| 122 | let variant: String = s.into_owned(); |
| 123 | visitor.visit_enum(variant.into_deserializer()) |
| 124 | } |
| 125 | Some(Token::OpenBrace) => { |
| 126 | // expect exactly one property: { "Variant": data } |
| 127 | let key = match self.scan()? { |
| 128 | Some(Token::String(s)) => s.into_owned(), |
| 129 | _ => { |
| 130 | return Err(ParseError::new( |
| 131 | token_range, |
| 132 | ParseErrorKind::Custom("expected a string key for enum variant".to_string()), |
| 133 | text, |
| 134 | )); |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | // expect colon |
| 139 | self.scan_object_colon()?; |
| 140 | |
| 141 | let result = visitor.visit_enum(ObjectEnumAccess { |
| 142 | parser: self, |
| 143 | variant: key, |
| 144 | }); |
| 145 | result.and_then(|v| { |
| 146 | // expect close brace |
| 147 | match self.scan()? { |
| 148 | Some(Token::CloseBrace) => Ok(v), |
| 149 | _ => Err( |
| 150 | self |
| 151 | .scanner |
| 152 | .create_error_for_current_token(ParseErrorKind::UnterminatedObject), |
| 153 | ), |
| 154 | } |
| 155 | }) |
| 156 | } |
| 157 | _ => { |
| 158 | return Err(ParseError::new( |
| 159 | token_range, |
| 160 | ParseErrorKind::Custom("expected a string or object for enum".to_string()), |
| 161 | text, |
| 162 | )); |
| 163 | } |
| 164 | }; |
| 165 | result.map_err(|e| e.with_position(token_range, text)) |
| 166 | } |
| 167 | |
| 168 | fn deserialize_newtype_struct<V: Visitor<'de>>( |
nothing calls this directly
no test coverage detected