File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " msgpacker"
3
- version = " 0.4.3 "
3
+ version = " 0.4.4 "
4
4
authors = [
" Victor Lopez <[email protected] >" ]
5
5
categories = [" compression" , " encoding" , " parser-implementations" ]
6
6
edition = " 2021"
Original file line number Diff line number Diff line change @@ -30,15 +30,36 @@ pub use extension::Extension;
30
30
#[ cfg( feature = "derive" ) ]
31
31
pub use msgpacker_derive:: MsgPacker ;
32
32
33
+ /// Packs the provided packable value into a vector.
34
+ pub fn pack_to_vec < T > ( value : & T ) -> Vec < u8 >
35
+ where
36
+ T : Packable ,
37
+ {
38
+ let mut bytes = Vec :: new ( ) ;
39
+
40
+ value. pack ( & mut bytes) ;
41
+
42
+ bytes
43
+ }
44
+
33
45
/// A packable type.
34
46
pub trait Packable {
35
47
/// Pack a value into the extendable buffer, returning the amount of written bytes.
36
48
fn pack < T > ( & self , buf : & mut T ) -> usize
37
49
where
38
50
T : Extend < u8 > ;
51
+
52
+ /// Packs the value into a vector of bytes.
53
+ fn pack_to_vec < T > ( & self ) -> Vec < u8 > {
54
+ let mut bytes = Vec :: new ( ) ;
55
+
56
+ self . pack ( & mut bytes) ;
57
+
58
+ bytes
59
+ }
39
60
}
40
61
41
- impl < ' a , X > Packable for & ' a X
62
+ impl < X > Packable for & X
42
63
where
43
64
X : Packable ,
44
65
{
50
71
}
51
72
}
52
73
53
- impl < ' a , X > Packable for & ' a mut X
74
+ impl < X > Packable for & mut X
54
75
where
55
76
X : Packable ,
56
77
{
You can’t perform that action at this time.
0 commit comments