File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -196,8 +196,29 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
196
196
}
197
197
}
198
198
199
+ fn deserialize_i32 < V > ( self , visitor : V ) -> Result < V :: Value , Self :: Error >
200
+ where
201
+ V : Visitor < ' de > ,
202
+ {
203
+ // Since the sync service is written in JavaScript, we'll get numbers as doubles...
204
+ let element_type = self . prepare_to_read_value ( ) ?;
205
+ match element_type {
206
+ ElementType :: Int32 => visitor. visit_i32 ( self . parser . read_int32 ( ) ?) ,
207
+ ElementType :: Double => {
208
+ let value = self . parser . read_double ( ) ?;
209
+ let converted: i32 = num_traits:: cast ( value) . ok_or_else ( || {
210
+ self . parser
211
+ . error ( ErrorKind :: IllegalFloatToIntConversion ( value) )
212
+ } ) ?;
213
+
214
+ visitor. visit_i32 ( converted)
215
+ }
216
+ _ => self . deserialize_any ( visitor) ,
217
+ }
218
+ }
219
+
199
220
forward_to_deserialize_any ! {
200
- bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
221
+ bool i8 i16 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
201
222
bytes byte_buf unit unit_struct newtype_struct seq tuple
202
223
tuple_struct map struct ignored_any identifier
203
224
}
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ pub enum ErrorKind {
36
36
InvalidStateExpectedValue ,
37
37
ExpectedEnum { actual : ElementType } ,
38
38
ExpectedString ,
39
+ IllegalFloatToIntConversion ( f64 ) ,
39
40
UnexpectedEndOfDocumentForEnumVariant ,
40
41
}
41
42
You can’t perform that action at this time.
0 commit comments