@@ -57,6 +57,14 @@ impl<'a> AnyRef<'a> {
5757 self . value . as_slice ( )
5858 }
5959
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+
6068 /// Attempt to decode this [`AnyRef`] type into the inner value.
6169 pub fn decode_as < T > ( self ) -> Result < T , <T as DecodeValue < ' a > >:: Error >
6270 where
@@ -77,13 +85,8 @@ impl<'a> AnyRef<'a> {
7785 return Err ( self . tag . unexpected_error ( None ) . to_error ( ) . into ( ) ) ;
7886 }
7987
80- let header = Header {
81- tag : self . tag ,
82- length : self . value . len ( ) ,
83- } ;
84-
8588 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 ( ) ) ?;
8790 decoder. finish ( ) ?;
8891 Ok ( result)
8992 }
@@ -205,6 +208,14 @@ mod allocating {
205208 self . value . as_slice ( )
206209 }
207210
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+
208219 /// Attempt to decode this [`Any`] type into the inner value.
209220 pub fn decode_as < ' a , T > ( & ' a self ) -> Result < T , <T as DecodeValue < ' a > >:: Error >
210221 where
@@ -221,7 +232,7 @@ mod allocating {
221232 where
222233 T : Choice < ' a > + DecodeValue < ' a > ,
223234 {
224- AnyRef :: from ( self ) . decode_as_encoding ( encoding)
235+ self . to_ref ( ) . decode_as_encoding ( encoding)
225236 }
226237
227238 /// Encode the provided type as an [`Any`] value.
0 commit comments