@@ -45,6 +45,7 @@ pub struct IonEncoderConfig {
45
45
46
46
impl IonEncoderConfig {
47
47
/// Set the mode to `mode`
48
+ #[ must_use]
48
49
pub fn with_mode ( mut self , mode : crate :: Encoding ) -> Self {
49
50
self . mode = mode;
50
51
self
@@ -66,6 +67,7 @@ pub struct IonEncoderBuilder {
66
67
67
68
impl IonEncoderBuilder {
68
69
/// Create the builder from 'config'
70
+ #[ must_use]
69
71
pub fn new ( config : IonEncoderConfig ) -> Self {
70
72
Self { config }
71
73
}
@@ -214,7 +216,7 @@ where
214
216
}
215
217
216
218
fn encode_decimal ( & mut self , val : & Decimal ) -> IonEncodeResult {
217
- let scale = val. scale ( ) as i64 ;
219
+ let scale = i64 :: from ( val. scale ( ) ) ;
218
220
let mantissa = val. mantissa ( ) ;
219
221
let dec = ion_rs:: Decimal :: new ( mantissa, -scale) ;
220
222
Ok ( self . writer . write_decimal ( & dec) ?)
@@ -234,9 +236,13 @@ where
234
236
let ts = ion_rs:: Timestamp :: with_ymd (
235
237
ts. year ( ) as u32 ,
236
238
ts. month ( ) as u32 ,
237
- ts. day ( ) as u32 ,
239
+ u32:: from ( ts. day ( ) ) ,
240
+ )
241
+ . with_hms (
242
+ u32:: from ( ts. hour ( ) ) ,
243
+ u32:: from ( ts. minute ( ) ) ,
244
+ u32:: from ( ts. second ( ) ) ,
238
245
)
239
- . with_hms ( ts. hour ( ) as u32 , ts. minute ( ) as u32 , ts. second ( ) as u32 )
240
246
. with_nanoseconds ( ts. nanosecond ( ) )
241
247
. build_at_unknown_offset ( ) ?;
242
248
@@ -246,11 +252,15 @@ where
246
252
let ts = ion_rs:: Timestamp :: with_ymd (
247
253
ts. year ( ) as u32 ,
248
254
ts. month ( ) as u32 ,
249
- ts. day ( ) as u32 ,
255
+ u32:: from ( ts. day ( ) ) ,
256
+ )
257
+ . with_hms (
258
+ u32:: from ( ts. hour ( ) ) ,
259
+ u32:: from ( ts. minute ( ) ) ,
260
+ u32:: from ( ts. second ( ) ) ,
250
261
)
251
- . with_hms ( ts. hour ( ) as u32 , ts. minute ( ) as u32 , ts. second ( ) as u32 )
252
262
. with_nanoseconds ( ts. nanosecond ( ) )
253
- . build_at_offset ( ts. offset ( ) . whole_minutes ( ) as i32 ) ?;
263
+ . build_at_offset ( i32 :: from ( ts. offset ( ) . whole_minutes ( ) ) ) ?;
254
264
255
265
Ok ( self . writer . write_timestamp ( & ts) ?)
256
266
}
@@ -324,9 +334,12 @@ where
324
334
self . inner
325
335
. writer
326
336
. set_annotations ( std:: iter:: once ( DATE_ANNOT ) ) ;
327
- let ts =
328
- ion_rs:: Timestamp :: with_ymd ( date. year ( ) as u32 , date. month ( ) as u32 , date. day ( ) as u32 )
329
- . build ( ) ?;
337
+ let ts = ion_rs:: Timestamp :: with_ymd (
338
+ date. year ( ) as u32 ,
339
+ date. month ( ) as u32 ,
340
+ u32:: from ( date. day ( ) ) ,
341
+ )
342
+ . build ( ) ?;
330
343
331
344
Ok ( self . inner . writer . write_timestamp ( & ts) ?)
332
345
}
@@ -336,19 +349,19 @@ where
336
349
writer. set_annotations ( std:: iter:: once ( TIME_ANNOT ) ) ;
337
350
writer. step_in ( IonType :: Struct ) ?;
338
351
writer. set_field_name ( TIME_PART_HOUR_KEY ) ;
339
- writer. write_i64 ( time. hour ( ) as i64 ) ?;
352
+ writer. write_i64 ( i64 :: from ( time. hour ( ) ) ) ?;
340
353
writer. set_field_name ( TIME_PART_MINUTE_KEY ) ;
341
- writer. write_i64 ( time. minute ( ) as i64 ) ?;
354
+ writer. write_i64 ( i64 :: from ( time. minute ( ) ) ) ?;
342
355
writer. set_field_name ( TIME_PART_SECOND_KEY ) ;
343
356
344
- let seconds = Duration :: new ( time. second ( ) as i64 , time. nanosecond ( ) as i32 ) ;
357
+ let seconds = Duration :: new ( i64 :: from ( time. second ( ) ) , time. nanosecond ( ) as i32 ) ;
345
358
writer. write_f64 ( seconds. as_seconds_f64 ( ) ) ?;
346
359
347
360
if let Some ( offset) = offset {
348
361
writer. set_field_name ( TIME_PART_TZ_HOUR_KEY ) ;
349
- writer. write_i64 ( offset. whole_hours ( ) as i64 ) ?;
362
+ writer. write_i64 ( i64 :: from ( offset. whole_hours ( ) ) ) ?;
350
363
writer. set_field_name ( TIME_PART_TZ_MINUTE_KEY ) ;
351
- writer. write_i64 ( offset. minutes_past_hour ( ) as i64 ) ?;
364
+ writer. write_i64 ( i64 :: from ( offset. minutes_past_hour ( ) ) ) ?;
352
365
}
353
366
354
367
writer. step_out ( ) ?;
0 commit comments