@@ -40,11 +40,13 @@ type ParseResult<'a> = Option<Parsed<'a>>;
4040
4141/// Parsing context
4242#[ derive( Clone , Copy , Debug , PartialEq ) ]
43+ // The default values are the most common setting for non top-level parsing: not top block, not at
44+ // line start (yes leading whitespace, not escaped).
4345struct Context {
4446 /// If true, we are at a the topmost level (not recursing a nested tt)
45- top_block : bool ,
47+ top_block : bool = false ,
4648 /// Previous character
47- prev : Prev ,
49+ prev : Prev = Prev :: Whitespace ,
4850}
4951
5052/// Character class preceding this one
@@ -57,14 +59,6 @@ enum Prev {
5759 Any ,
5860}
5961
60- impl Default for Context {
61- /// Most common setting for non top-level parsing: not top block, not at
62- /// line start (yes leading whitespace, not escaped)
63- fn default ( ) -> Self {
64- Self { top_block : false , prev : Prev :: Whitespace }
65- }
66- }
67-
6862/// Flags to simple parser function
6963#[ derive( Clone , Copy , Debug , PartialEq ) ]
7064enum ParseOpt {
@@ -248,7 +242,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
248242 }
249243
250244 let ( txt, rest) = parse_to_newline ( & buf[ 1 ..] ) ;
251- let ctx = Context { top_block : false , prev : Prev :: Whitespace } ;
245+ let ctx = Context { .. } ;
252246 let stream = parse_recursive ( txt, ctx) ;
253247
254248 Some ( ( MdTree :: Heading ( level. try_into ( ) . unwrap ( ) , stream) , rest) )
@@ -257,7 +251,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
257251/// Bulleted list
258252fn parse_unordered_li ( buf : & [ u8 ] ) -> Parsed < ' _ > {
259253 let ( txt, rest) = get_indented_section ( & buf[ 2 ..] ) ;
260- let ctx = Context { top_block : false , prev : Prev :: Whitespace } ;
254+ let ctx = Context { .. } ;
261255 let stream = parse_recursive ( trim_ascii_start ( txt) , ctx) ;
262256 ( MdTree :: UnorderedListItem ( stream) , rest)
263257}
@@ -266,7 +260,7 @@ fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
266260fn parse_ordered_li ( buf : & [ u8 ] ) -> Parsed < ' _ > {
267261 let ( num, pos) = ord_list_start ( buf) . unwrap ( ) ; // success tested in caller
268262 let ( txt, rest) = get_indented_section ( & buf[ pos..] ) ;
269- let ctx = Context { top_block : false , prev : Prev :: Whitespace } ;
263+ let ctx = Context { .. } ;
270264 let stream = parse_recursive ( trim_ascii_start ( txt) , ctx) ;
271265 ( MdTree :: OrderedListItem ( num, stream) , rest)
272266}
0 commit comments