1#![cfg_attr(
3 feature = "tracing",
4 allow(clippy::used_underscore_binding, reason = "Only used in tracing::instrument")
5)]
6
7use ::serde::de::{Error, IntoDeserializer, Unexpected};
8
9use super::*;
10
11#[derive(Debug)]
13pub struct ValueDeserializer<'de>(Value<'de>);
14
15impl<'de> ValueDeserializer<'de> {
16 #[must_use]
18 pub const fn new(value: Value<'de>) -> Self {
19 Self(value)
20 }
21
22 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
24 fn deserialize<V>(self, visitor: V) -> Result<V::Value>
25 where
26 V: ::serde::de::Visitor<'de>,
27 {
28 match self.0 {
29 Value::Null => visitor.visit_none(),
30 Value::Bool(b) => visitor.visit_bool(b),
31 Value::Integer(int) => visit_integer(int, visitor),
32 Value::Float(Float::F32(float)) => visitor.visit_f32(float),
33 Value::Float(Float::F64(float)) => visitor.visit_f64(float),
34 Value::Bytes(Cow::Borrowed(bytes)) => visitor.visit_borrowed_bytes(bytes),
35 Value::Bytes(Cow::Owned(bytes)) => visitor.visit_byte_buf(bytes),
36 Value::String(Cow::Borrowed(s)) => visitor.visit_borrowed_str(s),
37 Value::String(Cow::Owned(s)) => visitor.visit_string(s),
38 Value::Array(arr) => visitor.visit_seq(ValueSeqDeserializer(arr)),
39 Value::Map(map) => visitor.visit_map(ValueMapDeserializer(map)),
40 }
41 }
42}
43
44impl<'de> ::serde::de::Deserializer<'de> for ValueDeserializer<'de> {
45 type Error = crate::Error;
46
47 #[inline]
48 fn is_human_readable(&self) -> bool {
49 true
50 }
51
52 #[inline]
53 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
54 fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
55 where
56 V: serde::de::Visitor<'de>,
57 {
58 Self::deserialize(self, visitor)
59 }
60
61 #[inline]
62 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
63 fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
64 where
65 V: serde::de::Visitor<'de>,
66 {
67 match self.0 {
68 Value::Bool(value) => visitor.visit_bool(value),
69 other => Err(Error::invalid_type(Unexpected::from(&other), &"bool")),
70 }
71 }
72
73 #[inline]
74 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
75 fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
76 where
77 V: serde::de::Visitor<'de>,
78 {
79 match self.0 {
80 Value::Integer(int) => visit_integer(int, visitor),
81 other => Err(Error::invalid_type(Unexpected::from(&other), &"i8")),
82 }
83 }
84
85 #[inline]
86 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
87 fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
88 where
89 V: serde::de::Visitor<'de>,
90 {
91 match self.0 {
92 Value::Integer(int) => visit_integer(int, visitor),
93 other => Err(Error::invalid_type(Unexpected::from(&other), &"i16")),
94 }
95 }
96
97 #[inline]
98 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
99 fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
100 where
101 V: serde::de::Visitor<'de>,
102 {
103 match self.0 {
104 Value::Integer(int) => visit_integer(int, visitor),
105 other => Err(Error::invalid_type(Unexpected::from(&other), &"i32")),
106 }
107 }
108
109 #[inline]
110 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
111 fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
112 where
113 V: serde::de::Visitor<'de>,
114 {
115 match self.0 {
116 Value::Integer(int) => visit_integer(int, visitor),
117 other => Err(Error::invalid_type(Unexpected::from(&other), &"i64")),
118 }
119 }
120
121 #[inline]
122 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
123 fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error>
124 where
125 V: serde::de::Visitor<'de>,
126 {
127 match self.0 {
128 Value::Integer(int) => visit_integer(int, visitor),
129 other => Err(Error::invalid_type(Unexpected::from(&other), &"u8")),
130 }
131 }
132
133 #[inline]
134 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
135 fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error>
136 where
137 V: serde::de::Visitor<'de>,
138 {
139 match self.0 {
140 Value::Integer(int) => visit_integer(int, visitor),
141 other => Err(Error::invalid_type(Unexpected::from(&other), &"u16")),
142 }
143 }
144
145 #[inline]
146 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
147 fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
148 where
149 V: serde::de::Visitor<'de>,
150 {
151 match self.0 {
152 Value::Integer(int) => visit_integer(int, visitor),
153 other => Err(Error::invalid_type(Unexpected::from(&other), &"u32")),
154 }
155 }
156
157 #[inline]
158 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
159 fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
160 where
161 V: serde::de::Visitor<'de>,
162 {
163 match self.0 {
164 Value::Integer(int) => visit_integer(int, visitor),
165 other => Err(Error::invalid_type(Unexpected::from(&other), &"u64")),
166 }
167 }
168
169 #[inline]
170 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
171 fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Self::Error>
172 where
173 V: serde::de::Visitor<'de>,
174 {
175 match self.0 {
176 Value::Integer(int) => visit_integer(int, visitor),
177 other => Err(Error::invalid_type(Unexpected::from(&other), &"i128")),
178 }
179 }
180
181 #[inline]
182 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
183 fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Self::Error>
184 where
185 V: serde::de::Visitor<'de>,
186 {
187 match self.0 {
188 Value::Integer(int) => visit_integer(int, visitor),
189 other => Err(Error::invalid_type(Unexpected::from(&other), &"u128")),
190 }
191 }
192
193 #[inline]
194 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
195 fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error>
196 where
197 V: serde::de::Visitor<'de>,
198 {
199 match self.0 {
200 Value::Float(Float::F32(float)) => visitor.visit_f32(float),
201 Value::Float(Float::F64(float)) => visitor.visit_f64(float),
202 other => Err(Error::invalid_type(Unexpected::from(&other), &"float")),
203 }
204 }
205
206 #[inline]
207 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
208 fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
209 where
210 V: serde::de::Visitor<'de>,
211 {
212 match self.0 {
213 Value::Float(Float::F32(float)) => visitor.visit_f32(float),
214 Value::Float(Float::F64(float)) => visitor.visit_f64(float),
215 other => Err(Error::invalid_type(Unexpected::from(&other), &"float")),
216 }
217 }
218
219 #[inline]
220 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
221 fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
222 where
223 V: serde::de::Visitor<'de>,
224 {
225 match self.0 {
226 Value::String(Cow::Borrowed(s)) => visitor.visit_borrowed_str(s),
227 Value::String(Cow::Owned(s)) => visitor.visit_string(s),
228 other => Err(Error::invalid_type(Unexpected::from(&other), &"char")),
229 }
230 }
231
232 #[inline]
233 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
234 fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
235 where
236 V: serde::de::Visitor<'de>,
237 {
238 match self.0 {
239 Value::String(Cow::Borrowed(s)) => visitor.visit_borrowed_str(s),
240 Value::String(Cow::Owned(s)) => visitor.visit_string(s),
241 other => Err(Error::invalid_type(Unexpected::from(&other), &"string")),
242 }
243 }
244
245 #[inline]
246 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
247 fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
248 where
249 V: serde::de::Visitor<'de>,
250 {
251 match self.0 {
252 Value::String(Cow::Borrowed(s)) => visitor.visit_borrowed_str(s),
253 Value::String(Cow::Owned(s)) => visitor.visit_string(s),
254 other => Err(Error::invalid_type(Unexpected::from(&other), &"string")),
255 }
256 }
257
258 #[inline]
259 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
260 fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>
261 where
262 V: serde::de::Visitor<'de>,
263 {
264 match self.0 {
265 Value::Bytes(Cow::Borrowed(bytes)) => visitor.visit_borrowed_bytes(bytes),
266 Value::Bytes(Cow::Owned(bytes)) => visitor.visit_byte_buf(bytes),
267 other => Err(Error::invalid_type(Unexpected::from(&other), &"bytes")),
268 }
269 }
270
271 #[inline]
272 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
273 fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>
274 where
275 V: serde::de::Visitor<'de>,
276 {
277 match self.0 {
278 Value::Bytes(Cow::Borrowed(bytes)) => visitor.visit_borrowed_bytes(bytes),
279 Value::Bytes(Cow::Owned(bytes)) => visitor.visit_byte_buf(bytes),
280 other => Err(Error::invalid_type(Unexpected::from(&other), &"bytes")),
281 }
282 }
283
284 #[inline]
285 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
286 fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>
287 where
288 V: serde::de::Visitor<'de>,
289 {
290 if matches!(&self.0, Value::Null) {
291 visitor.visit_none()
292 } else {
293 visitor.visit_some(self)
294 }
295 }
296
297 #[inline]
298 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
299 fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>
300 where
301 V: serde::de::Visitor<'de>,
302 {
303 match self.0 {
304 Value::Null => visitor.visit_unit(),
305 other => Err(Error::invalid_type(Unexpected::from(&other), &"unit")),
306 }
307 }
308
309 #[inline]
310 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
311 fn deserialize_unit_struct<V>(
312 self,
313 _name: &'static str,
314 visitor: V,
315 ) -> Result<V::Value, Self::Error>
316 where
317 V: serde::de::Visitor<'de>,
318 {
319 match self.0 {
320 Value::Null => visitor.visit_unit(),
321 other => Err(Error::invalid_type(Unexpected::from(&other), &"unit")),
322 }
323 }
324
325 #[inline]
326 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
327 fn deserialize_newtype_struct<V>(
328 self,
329 _name: &'static str,
330 visitor: V,
331 ) -> Result<V::Value, Self::Error>
332 where
333 V: serde::de::Visitor<'de>,
334 {
335 visitor.visit_newtype_struct(self)
336 }
337
338 #[inline]
339 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
340 fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>
341 where
342 V: serde::de::Visitor<'de>,
343 {
344 match self.0 {
345 Value::Array(arr) => visitor.visit_seq(ValueSeqDeserializer(arr)),
346 other => Err(Error::invalid_type(Unexpected::from(&other), &"sequence")),
347 }
348 }
349
350 #[inline]
351 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
352 fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
353 where
354 V: serde::de::Visitor<'de>,
355 {
356 match self.0 {
357 Value::Array(arr) => visitor.visit_seq(ValueSeqDeserializer(arr)),
358 other => Err(Error::invalid_type(Unexpected::from(&other), &"tuple")),
359 }
360 }
361
362 #[inline]
363 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
364 fn deserialize_tuple_struct<V>(
365 self,
366 _name: &'static str,
367 _len: usize,
368 visitor: V,
369 ) -> Result<V::Value, Self::Error>
370 where
371 V: serde::de::Visitor<'de>,
372 {
373 match self.0 {
374 Value::Array(arr) => visitor.visit_seq(ValueSeqDeserializer(arr)),
375 other => Err(Error::invalid_type(Unexpected::from(&other), &"tuple struct")),
376 }
377 }
378
379 #[inline]
380 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
381 fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>
382 where
383 V: serde::de::Visitor<'de>,
384 {
385 match self.0 {
386 Value::Map(map) => visitor.visit_map(ValueMapDeserializer(map)),
387 other => Err(Error::invalid_type(Unexpected::from(&other), &"map")),
388 }
389 }
390
391 #[inline]
392 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
393 fn deserialize_struct<V>(
394 self,
395 _name: &'static str,
396 _fields: &'static [&'static str],
397 visitor: V,
398 ) -> Result<V::Value, Self::Error>
399 where
400 V: serde::de::Visitor<'de>,
401 {
402 match self.0 {
403 Value::Map(map) => visitor.visit_map(ValueMapDeserializer(map)),
404 other => Err(Error::invalid_type(Unexpected::from(&other), &"map")),
405 }
406 }
407
408 #[inline]
409 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
410 fn deserialize_enum<V>(
411 self,
412 _name: &'static str,
413 _variants: &'static [&'static str],
414 visitor: V,
415 ) -> Result<V::Value, Self::Error>
416 where
417 V: serde::de::Visitor<'de>,
418 {
419 match self.0 {
420 Value::Integer(Integer::Unsigned(int)) => {
421 visitor.visit_enum((int as u32).into_deserializer())
422 }
423 Value::String(s) => visitor.visit_enum(s.as_ref().into_deserializer()),
424 Value::Map(map) => visitor.visit_enum(ValueEnumDeserializer(map)),
425 other => Err(Error::invalid_type(Unexpected::from(&other), &"enum")),
426 }
427 }
428
429 #[inline]
430 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
431 fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
432 where
433 V: serde::de::Visitor<'de>,
434 {
435 match self.0 {
436 Value::Integer(Integer::Unsigned(_)) => self.deserialize_u32(visitor),
437 Value::String(_) => self.deserialize_str(visitor),
438 other => Err(Error::invalid_type(Unexpected::from(&other), &"identifier")),
439 }
440 }
441
442 #[inline]
443 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
444 fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
445 where
446 V: serde::de::Visitor<'de>,
447 {
448 self.deserialize_any(visitor)
449 }
450}
451
452#[derive(Debug)]
454struct ValueEnumDeserializer<'de>(VecDeque<(Value<'de>, Value<'de>)>);
455
456impl<'de> ::serde::de::EnumAccess<'de> for ValueEnumDeserializer<'de> {
457 type Error = crate::Error;
458 type Variant = ValueDeserializer<'de>;
459
460 #[inline]
461 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
462 fn variant_seed<V>(mut self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error>
463 where
464 V: serde::de::DeserializeSeed<'de>,
465 {
466 if self.0.len() != 1 {
467 return Err(Error::invalid_length(1, &"exactly one key-value-pair"));
468 }
469
470 #[expect(clippy::unwrap_used, reason = "Was just checked")]
471 let (key, value) = self.0.pop_front().unwrap();
472 let res = seed.deserialize(ValueDeserializer(key))?;
473 Ok((res, ValueDeserializer(value)))
474 }
475}
476
477impl<'de> ::serde::de::VariantAccess<'de> for ValueDeserializer<'de> {
478 type Error = crate::Error;
479
480 #[inline]
481 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
482 fn unit_variant(self) -> Result<(), Self::Error> {
483 Err(Error::invalid_type(Unexpected::from(&self.0), &"unit variant"))
484 }
485
486 #[inline]
487 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
488 fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
489 where
490 T: serde::de::DeserializeSeed<'de>,
491 {
492 seed.deserialize(self)
493 }
494
495 #[inline]
496 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
497 fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
498 where
499 V: serde::de::Visitor<'de>,
500 {
501 ::serde::de::Deserializer::deserialize_seq(self, visitor)
502 }
503
504 #[inline]
505 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip(self, visitor)))]
506 fn struct_variant<V>(
507 self,
508 _fields: &'static [&'static str],
509 visitor: V,
510 ) -> Result<V::Value, Self::Error>
511 where
512 V: serde::de::Visitor<'de>,
513 {
514 ::serde::de::Deserializer::deserialize_map(self, visitor)
515 }
516}
517
518#[derive(Debug)]
520struct ValueSeqDeserializer<'de>(VecDeque<Value<'de>>);
521
522impl<'de> ::serde::de::SeqAccess<'de> for ValueSeqDeserializer<'de> {
523 type Error = crate::Error;
524
525 #[inline]
526 fn size_hint(&self) -> Option<usize> {
527 Some(self.0.len())
528 }
529
530 #[inline]
531 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
532 fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
533 where
534 T: serde::de::DeserializeSeed<'de>,
535 {
536 if let Some(value) = self.0.pop_front() {
537 seed.deserialize(ValueDeserializer(value)).map(Some)
538 } else {
539 Ok(None)
540 }
541 }
542}
543
544#[derive(Debug)]
546struct ValueMapDeserializer<'de>(VecDeque<(Value<'de>, Value<'de>)>);
547
548impl<'de> ::serde::de::MapAccess<'de> for ValueMapDeserializer<'de> {
549 type Error = crate::Error;
550
551 #[inline]
552 fn size_hint(&self) -> Option<usize> {
553 Some(self.0.len())
554 }
555
556 #[inline]
557 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
558 fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error>
559 where
560 K: serde::de::DeserializeSeed<'de>,
561 {
562 if let Some((key, _value)) = self.0.front_mut() {
563 let value = ::core::mem::replace(key, Value::Null);
564 Ok(Some(seed.deserialize(ValueDeserializer(value))?))
565 } else {
566 Ok(None)
567 }
568 }
569
570 #[inline]
571 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
572 fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error>
573 where
574 V: serde::de::DeserializeSeed<'de>,
575 {
576 if let Some((_key, value)) = self.0.pop_front() {
577 Ok(seed.deserialize(ValueDeserializer(value))?)
578 } else {
579 Err(Error::custom("next_value_seed called without next_key_seed"))
580 }
581 }
582
583 #[inline]
584 #[cfg_attr(feature = "tracing", ::tracing::instrument(skip_all))]
585 #[allow(clippy::type_complexity, reason = "Tracing makes this trigger, also it's serde trait")]
586 fn next_entry_seed<K, V>(
587 &mut self,
588 kseed: K,
589 vseed: V,
590 ) -> Result<Option<(K::Value, V::Value)>, Self::Error>
591 where
592 K: serde::de::DeserializeSeed<'de>,
593 V: serde::de::DeserializeSeed<'de>,
594 {
595 if let Some((key, value)) = self.0.pop_front() {
596 let key = kseed.deserialize(ValueDeserializer(key))?;
597 let value = vseed.deserialize(ValueDeserializer(value))?;
598 Ok(Some((key, value)))
599 } else {
600 Ok(None)
601 }
602 }
603}
604
605#[cfg_attr(feature = "tracing", ::tracing::instrument(skip(visitor)))]
607fn visit_integer<'de, V>(int: Integer, visitor: V) -> Result<V::Value>
608where
609 V: ::serde::de::Visitor<'de>,
610{
611 #[allow(clippy::cast_lossless, reason = "We won't change it")]
612 match int {
613 Integer::Unsigned(int) if int <= u8::MAX as u128 => visitor.visit_u8(int as u8),
614 Integer::Unsigned(int) if int <= u16::MAX as u128 => visitor.visit_u16(int as u16),
615 Integer::Unsigned(int) if int <= u32::MAX as u128 => visitor.visit_u32(int as u32),
616 Integer::Unsigned(int) if int <= u64::MAX as u128 => visitor.visit_u64(int as u64),
617 Integer::Unsigned(int) => visitor.visit_u128(int),
618 Integer::Signed(int) if (i8::MIN as i128 ..= i8::MAX as i128).contains(&int) => {
619 visitor.visit_i8(int as i8)
620 }
621 Integer::Signed(int) if (i16::MIN as i128 ..= i16::MAX as i128).contains(&int) => {
622 visitor.visit_i16(int as i16)
623 }
624 Integer::Signed(int) if (i32::MIN as i128 ..= i32::MAX as i128).contains(&int) => {
625 visitor.visit_i32(int as i32)
626 }
627 Integer::Signed(int) if (i64::MIN as i128 ..= i64::MAX as i128).contains(&int) => {
628 visitor.visit_i64(int as i64)
629 }
630 Integer::Signed(int) => visitor.visit_i128(int),
631 }
632}
633
634impl<'a, 'de> From<&'a Value<'de>> for Unexpected<'a> {
635 fn from(value: &'a Value<'de>) -> Self {
636 match value {
637 Value::Null => Unexpected::Unit,
638 Value::Bool(b) => Unexpected::Bool(*b),
639 Value::Integer(Integer::Unsigned(int)) => Unexpected::Unsigned(*int as u64),
640 Value::Integer(Integer::Signed(int)) => Unexpected::Signed(*int as i64),
641 Value::Float(Float::F32(float)) => Unexpected::Float(f64::from(*float)),
642 Value::Float(Float::F64(float)) => Unexpected::Float(*float),
643 Value::Bytes(bytes) => Unexpected::Bytes(bytes),
644 Value::String(s) => Unexpected::Str(s),
645 Value::Array(_arr) => Unexpected::Seq,
646 Value::Map(_map) => Unexpected::Map,
647 }
648 }
649}