File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,16 @@ where
156156 }
157157}
158158
159+ impl < Enc , Dec > Default for CborCodec < Enc , Dec >
160+ where
161+ for < ' de > Dec : Deserialize < ' de > + ' static ,
162+ for < ' de > Enc : Serialize + ' static ,
163+ {
164+ fn default ( ) -> Self {
165+ Self :: new ( )
166+ }
167+ }
168+
159169#[ cfg( test) ]
160170mod test {
161171 use bytes:: BytesMut ;
@@ -198,7 +208,7 @@ mod test {
198208 name : "Test name" . to_owned ( ) ,
199209 data : 34 ,
200210 } ;
201- codec. encode ( item1. clone ( ) , & mut buff) . unwrap ( ) ;
211+ codec. encode ( item1, & mut buff) . unwrap ( ) ;
202212
203213 let mut start = buff. clone ( ) . split_to ( 4 ) ;
204214 assert_eq ! ( codec. decode( & mut start) . unwrap( ) , None ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ use crate::{Decoder, Encoder};
44use bytes:: { Buf , BufMut , BytesMut } ;
55
66use serde:: { Deserialize , Serialize } ;
7- use serde_json;
87
98/// A codec for JSON encoding and decoding using serde_json
109/// Enc is the type to encode, Dec is the type to decode
@@ -154,6 +153,18 @@ where
154153 }
155154}
156155
156+
157+ impl < Enc , Dec > Default for JsonCodec < Enc , Dec >
158+ where
159+ for < ' de > Dec : Deserialize < ' de > + ' static ,
160+ for < ' de > Enc : Serialize + ' static ,
161+ {
162+ fn default ( ) -> Self {
163+ Self :: new ( )
164+ }
165+ }
166+
167+
157168#[ cfg( test) ]
158169mod test {
159170 use bytes:: BytesMut ;
@@ -196,7 +207,7 @@ mod test {
196207 name : "Test name" . to_owned ( ) ,
197208 data : 34 ,
198209 } ;
199- codec. encode ( item1. clone ( ) , & mut buff) . unwrap ( ) ;
210+ codec. encode ( item1, & mut buff) . unwrap ( ) ;
200211
201212 let mut start = buff. clone ( ) . split_to ( 4 ) ;
202213 assert_eq ! ( codec. decode( & mut start) . unwrap( ) , None ) ;
You can’t perform that action at this time.
0 commit comments