44 crate :: payload:: AggregatedPriceFeedData ,
55 anyhow:: { bail, Context } ,
66 itertools:: Itertools ,
7- protobuf:: { well_known_types:: timestamp:: Timestamp , MessageField } ,
7+ protobuf:: well_known_types:: timestamp:: Timestamp ,
88 rust_decimal:: { prelude:: FromPrimitive , Decimal } ,
99 serde:: { de:: Error , Deserialize , Serialize } ,
1010 std:: {
@@ -27,17 +27,13 @@ pub struct ChannelId(pub u8);
2727#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord , Serialize , Deserialize ) ]
2828pub struct TimestampUs ( pub u64 ) ;
2929
30- impl TryFrom < & MessageField < Timestamp > > for TimestampUs {
30+ impl TryFrom < & Timestamp > for TimestampUs {
3131 type Error = anyhow:: Error ;
3232
33- fn try_from ( timestamp_field : & MessageField < Timestamp > ) -> anyhow:: Result < Self > {
34- if let Some ( timestamp) = timestamp_field. clone ( ) . into_option ( ) {
35- let seconds_in_micros: u64 = ( timestamp. seconds * 1_000_000 ) . try_into ( ) ?;
36- let nanos_in_micros: u64 = ( timestamp. nanos / 1_000 ) . try_into ( ) ?;
37- Ok ( TimestampUs ( seconds_in_micros + nanos_in_micros) )
38- } else {
39- bail ! ( "timestamp field was empty" )
40- }
33+ fn try_from ( timestamp : & Timestamp ) -> anyhow:: Result < Self > {
34+ let seconds_in_micros: u64 = ( timestamp. seconds * 1_000_000 ) . try_into ( ) ?;
35+ let nanos_in_micros: u64 = ( timestamp. nanos / 1_000 ) . try_into ( ) ?;
36+ Ok ( TimestampUs ( seconds_in_micros + nanos_in_micros) )
4137 }
4238}
4339
0 commit comments