File tree Expand file tree Collapse file tree 2 files changed +19
-19
lines changed Expand file tree Collapse file tree 2 files changed +19
-19
lines changed Original file line number Diff line number Diff line change @@ -4,25 +4,16 @@ mod mutation;
4
4
5
5
use mutation:: Mutation ;
6
6
7
+ // Implement the metadata trait for our mutation
8
+ // type. Will will use the standard library for the implementation
9
+ // details.
7
10
impl metadata:: MetadataRoundtrip for Mutation {
8
11
fn encode ( & self ) -> Result < Vec < u8 > , metadata:: MetadataError > {
9
- let mut rv = vec ! [ ] ;
10
- rv. extend ( self . effect_size . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
11
- rv. extend ( self . dominance . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
12
- rv. extend ( self . origin_time . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
13
- Ok ( rv)
12
+ Ok ( bincode:: serialize ( & self ) . unwrap ( ) )
14
13
}
15
14
16
15
fn decode ( md : & [ u8 ] ) -> Result < Self , metadata:: MetadataError > {
17
- use std:: convert:: TryInto ;
18
- let ( effect_size_bytes, rest) = md. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
19
- let ( dominance_bytes, rest) = rest. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
20
- let ( origin_time_bytes, _) = rest. split_at ( std:: mem:: size_of :: < i32 > ( ) ) ;
21
- Ok ( Self {
22
- effect_size : f64:: from_le_bytes ( effect_size_bytes. try_into ( ) . unwrap ( ) ) ,
23
- dominance : f64:: from_le_bytes ( dominance_bytes. try_into ( ) . unwrap ( ) ) ,
24
- origin_time : i32:: from_le_bytes ( origin_time_bytes. try_into ( ) . unwrap ( ) ) ,
25
- } )
16
+ Ok ( bincode:: deserialize ( md) . unwrap ( ) )
26
17
}
27
18
}
28
19
Original file line number Diff line number Diff line change @@ -4,16 +4,25 @@ mod mutation;
4
4
5
5
use mutation:: Mutation ;
6
6
7
- // Implement the metadata trait for our mutation
8
- // type. Will will use the standard library for the implementation
9
- // details.
10
7
impl metadata:: MetadataRoundtrip for Mutation {
11
8
fn encode ( & self ) -> Result < Vec < u8 > , metadata:: MetadataError > {
12
- Ok ( bincode:: serialize ( & self ) . unwrap ( ) )
9
+ let mut rv = vec ! [ ] ;
10
+ rv. extend ( self . effect_size . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
11
+ rv. extend ( self . dominance . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
12
+ rv. extend ( self . origin_time . to_le_bytes ( ) . iter ( ) . copied ( ) ) ;
13
+ Ok ( rv)
13
14
}
14
15
15
16
fn decode ( md : & [ u8 ] ) -> Result < Self , metadata:: MetadataError > {
16
- Ok ( bincode:: deserialize ( md) . unwrap ( ) )
17
+ use std:: convert:: TryInto ;
18
+ let ( effect_size_bytes, rest) = md. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
19
+ let ( dominance_bytes, rest) = rest. split_at ( std:: mem:: size_of :: < f64 > ( ) ) ;
20
+ let ( origin_time_bytes, _) = rest. split_at ( std:: mem:: size_of :: < i32 > ( ) ) ;
21
+ Ok ( Self {
22
+ effect_size : f64:: from_le_bytes ( effect_size_bytes. try_into ( ) . unwrap ( ) ) ,
23
+ dominance : f64:: from_le_bytes ( dominance_bytes. try_into ( ) . unwrap ( ) ) ,
24
+ origin_time : i32:: from_le_bytes ( origin_time_bytes. try_into ( ) . unwrap ( ) ) ,
25
+ } )
17
26
}
18
27
}
19
28
You can’t perform that action at this time.
0 commit comments