1
1
use std:: borrow:: Borrow ;
2
2
use std:: convert:: TryFrom ;
3
- use std:: { cmp, fmt, hash} ;
3
+ use std:: { cmp, fmt, hash, ops } ;
4
4
5
5
use unsigned_varint:: { decode as varint_decode, encode as varint_encode} ;
6
6
@@ -87,6 +87,14 @@ impl AsRef<[u8]> for Multihash {
87
87
}
88
88
}
89
89
90
+ impl ops:: Deref for Multihash {
91
+ type Target = [ u8 ] ;
92
+
93
+ fn deref ( & self ) -> & Self :: Target {
94
+ & self . as_bytes ( )
95
+ }
96
+ }
97
+
90
98
impl Borrow < [ u8 ] > for Multihash {
91
99
fn borrow ( & self ) -> & [ u8 ] {
92
100
self . as_bytes ( )
@@ -107,6 +115,12 @@ impl TryFrom<Vec<u8>> for Multihash {
107
115
}
108
116
}
109
117
118
+ impl Into < Vec < u8 > > for Multihash {
119
+ fn into ( self ) -> Vec < u8 > {
120
+ self . to_vec ( )
121
+ }
122
+ }
123
+
110
124
impl PartialOrd for Multihash {
111
125
fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
112
126
Some ( self . cmp ( other) )
@@ -180,6 +194,20 @@ impl<'a> PartialEq<Multihash> for MultihashRef<'a> {
180
194
}
181
195
}
182
196
197
+ impl < ' a > ops:: Deref for MultihashRef < ' a > {
198
+ type Target = [ u8 ] ;
199
+
200
+ fn deref ( & self ) -> & Self :: Target {
201
+ self . as_bytes ( )
202
+ }
203
+ }
204
+
205
+ impl < ' a > Into < Vec < u8 > > for MultihashRef < ' a > {
206
+ fn into ( self ) -> Vec < u8 > {
207
+ self . to_vec ( )
208
+ }
209
+ }
210
+
183
211
/// The `MultihashDigest` trait specifies an interface common for all multihash functions.
184
212
pub trait MultihashDigest {
185
213
/// The Mutlihash byte value.
0 commit comments