core_json_traits/
primitives.rs

1use crate::{BytesLike, Stack, JsonError, Value, JsonDeserialize};
2
3impl JsonDeserialize for i8 {
4  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
5    value: Value<'bytes, 'parent, B, S>,
6  ) -> Result<Self, JsonError<'bytes, B, S>> {
7    value.as_i64()?.try_into().map_err(|_| JsonError::TypeError)
8  }
9}
10impl JsonDeserialize for i16 {
11  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
12    value: Value<'bytes, 'parent, B, S>,
13  ) -> Result<Self, JsonError<'bytes, B, S>> {
14    value.as_i64()?.try_into().map_err(|_| JsonError::TypeError)
15  }
16}
17impl JsonDeserialize for i32 {
18  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
19    value: Value<'bytes, 'parent, B, S>,
20  ) -> Result<Self, JsonError<'bytes, B, S>> {
21    value.as_i64()?.try_into().map_err(|_| JsonError::TypeError)
22  }
23}
24impl JsonDeserialize for i64 {
25  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
26    value: Value<'bytes, 'parent, B, S>,
27  ) -> Result<Self, JsonError<'bytes, B, S>> {
28    value.as_i64()
29  }
30}
31
32impl JsonDeserialize for u8 {
33  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
34    value: Value<'bytes, 'parent, B, S>,
35  ) -> Result<Self, JsonError<'bytes, B, S>> {
36    value.as_i64()?.try_into().map_err(|_| JsonError::TypeError)
37  }
38}
39impl JsonDeserialize for u16 {
40  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
41    value: Value<'bytes, 'parent, B, S>,
42  ) -> Result<Self, JsonError<'bytes, B, S>> {
43    value.as_i64()?.try_into().map_err(|_| JsonError::TypeError)
44  }
45}
46impl JsonDeserialize for u32 {
47  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
48    value: Value<'bytes, 'parent, B, S>,
49  ) -> Result<Self, JsonError<'bytes, B, S>> {
50    value.as_i64()?.try_into().map_err(|_| JsonError::TypeError)
51  }
52}
53impl JsonDeserialize for u64 {
54  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
55    value: Value<'bytes, 'parent, B, S>,
56  ) -> Result<Self, JsonError<'bytes, B, S>> {
57    value.as_i64()?.try_into().map_err(|_| JsonError::TypeError)
58  }
59}
60
61impl JsonDeserialize for f64 {
62  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
63    value: Value<'bytes, 'parent, B, S>,
64  ) -> Result<Self, JsonError<'bytes, B, S>> {
65    value.as_f64()
66  }
67}
68
69impl JsonDeserialize for bool {
70  fn deserialize<'bytes, 'parent, B: BytesLike<'bytes>, S: Stack>(
71    value: Value<'bytes, 'parent, B, S>,
72  ) -> Result<Self, JsonError<'bytes, B, S>> {
73    value.as_bool()
74  }
75}