File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,8 @@ impl<'a> Parser<'a> {
231231 Parser :: new ( self . data )
232232 }
233233
234- pub ( crate ) fn peek_tag ( & mut self ) -> Option < Tag > {
234+ /// Returns the tag of the next element, without consuming it.
235+ pub fn peek_tag ( & mut self ) -> Option < Tag > {
235236 let ( tag, _) = Tag :: from_bytes ( self . data ) . ok ( ) ?;
236237 Some ( tag)
237238 }
@@ -562,6 +563,15 @@ mod tests {
562563 assert_eq ! ( result, Err ( ParseError :: new( ParseErrorKind :: ExtraData ) ) ) ;
563564 }
564565
566+ #[ test]
567+ fn test_peek_tag ( ) {
568+ let result = crate :: parse ( b"\x02 \x01 \x7f " , |p| {
569+ assert_eq ! ( p. peek_tag( ) , Some ( Tag :: primitive( 0x02 ) ) ) ;
570+ p. read_element :: < u8 > ( )
571+ } ) ;
572+ assert_eq ! ( result, Ok ( 127 ) ) ;
573+ }
574+
565575 #[ test]
566576 fn test_errors ( ) {
567577 #[ derive( Debug , PartialEq , Eq ) ]
You can’t perform that action at this time.
0 commit comments