File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 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> {
196196 }
197197 }
198198
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+
199220 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
201222 bytes byte_buf unit unit_struct newtype_struct seq tuple
202223 tuple_struct map struct ignored_any identifier
203224 }
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ pub enum ErrorKind {
3636 InvalidStateExpectedValue ,
3737 ExpectedEnum { actual : ElementType } ,
3838 ExpectedString ,
39+ IllegalFloatToIntConversion ( f64 ) ,
3940 UnexpectedEndOfDocumentForEnumVariant ,
4041}
4142
You can’t perform that action at this time.
0 commit comments