@@ -40,11 +40,13 @@ type ParseResult<'a> = Option<Parsed<'a>>;
40
40
41
41
/// Parsing context
42
42
#[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).
43
45
struct Context {
44
46
/// If true, we are at a the topmost level (not recursing a nested tt)
45
- top_block : bool ,
47
+ top_block: bool = false ,
46
48
/// Previous character
47
- prev : Prev ,
49
+ prev: Prev = Prev::Whitespace ,
48
50
}
49
51
50
52
/// Character class preceding this one
@@ -57,14 +59,6 @@ enum Prev {
57
59
Any,
58
60
}
59
61
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
-
68
62
/// Flags to simple parser function
69
63
#[derive(Clone, Copy, Debug, PartialEq)]
70
64
enum ParseOpt {
@@ -248,7 +242,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
248
242
}
249
243
250
244
let (txt, rest) = parse_to_newline(&buf[1..]);
251
- let ctx = Context { top_block : false , prev : Prev :: Whitespace } ;
245
+ let ctx = Context { .. };
252
246
let stream = parse_recursive(txt, ctx);
253
247
254
248
Some((MdTree::Heading(level.try_into().unwrap(), stream), rest))
@@ -257,7 +251,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
257
251
/// Bulleted list
258
252
fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
259
253
let (txt, rest) = get_indented_section(&buf[2..]);
260
- let ctx = Context { top_block : false , prev : Prev :: Whitespace } ;
254
+ let ctx = Context { .. };
261
255
let stream = parse_recursive(trim_ascii_start(txt), ctx);
262
256
(MdTree::UnorderedListItem(stream), rest)
263
257
}
@@ -266,7 +260,7 @@ fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
266
260
fn parse_ordered_li(buf: &[u8]) -> Parsed<'_> {
267
261
let (num, pos) = ord_list_start(buf).unwrap(); // success tested in caller
268
262
let (txt, rest) = get_indented_section(&buf[pos..]);
269
- let ctx = Context { top_block : false , prev : Prev :: Whitespace } ;
263
+ let ctx = Context { .. };
270
264
let stream = parse_recursive(trim_ascii_start(txt), ctx);
271
265
(MdTree::OrderedListItem(num, stream), rest)
272
266
}
0 commit comments