@@ -57,6 +57,14 @@ impl<'a> AnyRef<'a> {
57
57
self . value . as_slice ( )
58
58
}
59
59
60
+ /// Returns [`Tag`] and [`Length`] of self.
61
+ pub fn header ( & self ) -> Header {
62
+ Header {
63
+ tag : self . tag ,
64
+ length : self . value . len ( ) ,
65
+ }
66
+ }
67
+
60
68
/// Attempt to decode this [`AnyRef`] type into the inner value.
61
69
pub fn decode_as < T > ( self ) -> Result < T , <T as DecodeValue < ' a > >:: Error >
62
70
where
@@ -77,13 +85,8 @@ impl<'a> AnyRef<'a> {
77
85
return Err ( self . tag . unexpected_error ( None ) . to_error ( ) . into ( ) ) ;
78
86
}
79
87
80
- let header = Header {
81
- tag : self . tag ,
82
- length : self . value . len ( ) ,
83
- } ;
84
-
85
88
let mut decoder = SliceReader :: new_with_encoding_rules ( self . value ( ) , encoding) ?;
86
- let result = T :: decode_value ( & mut decoder, header) ?;
89
+ let result = T :: decode_value ( & mut decoder, self . header ( ) ) ?;
87
90
decoder. finish ( ) ?;
88
91
Ok ( result)
89
92
}
@@ -205,6 +208,14 @@ mod allocating {
205
208
self . value . as_slice ( )
206
209
}
207
210
211
+ /// Returns [`Tag`] and [`Length`] of self.
212
+ pub fn header ( & self ) -> Header {
213
+ Header {
214
+ tag : self . tag ,
215
+ length : self . value . len ( ) ,
216
+ }
217
+ }
218
+
208
219
/// Attempt to decode this [`Any`] type into the inner value.
209
220
pub fn decode_as < ' a , T > ( & ' a self ) -> Result < T , <T as DecodeValue < ' a > >:: Error >
210
221
where
@@ -221,7 +232,7 @@ mod allocating {
221
232
where
222
233
T : Choice < ' a > + DecodeValue < ' a > ,
223
234
{
224
- AnyRef :: from ( self ) . decode_as_encoding ( encoding)
235
+ self . to_ref ( ) . decode_as_encoding ( encoding)
225
236
}
226
237
227
238
/// Encode the provided type as an [`Any`] value.
0 commit comments