From fd860a975b84da9a79abfa247787e6adbd5ea34c Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 5 Jul 2022 13:03:09 +0200 Subject: Refactor code style --- src/construct/thematic_break.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/construct/thematic_break.rs') diff --git a/src/construct/thematic_break.rs b/src/construct/thematic_break.rs index 8d29157..28aca34 100644 --- a/src/construct/thematic_break.rs +++ b/src/construct/thematic_break.rs @@ -95,7 +95,7 @@ impl Kind { /// /// ## Panics /// - /// Panics if `char` is not `*`, `_`, or `_`. + /// Panics if `char` is not `*`, `-`, or `_`. fn from_char(char: char) -> Kind { match char { '*' => Kind::Asterisk, @@ -104,6 +104,19 @@ impl Kind { _ => unreachable!("invalid char"), } } + /// Turn [Code] into a kind. + /// + /// > 👉 **Note**: an opening paren must be used for `Kind::Paren`. + /// + /// ## Panics + /// + /// Panics if `code` is not `Code::Char('*' | '-' | '_')`. + fn from_code(code: Code) -> Kind { + match code { + Code::Char(char) => Kind::from_char(char), + _ => unreachable!("invalid code"), + } + } } /// State needed to parse thematic breaks. @@ -133,11 +146,11 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { /// ``` fn before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult { match code { - Code::Char(char) if char == '*' || char == '-' || char == '_' => at_break( + Code::Char('*' | '-' | '_') => at_break( tokenizer, code, Info { - kind: Kind::from_char(char), + kind: Kind::from_code(code), size: 0, }, ), -- cgit