aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/thematic_break.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-05 13:03:09 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-05 13:03:09 +0200
commitfd860a975b84da9a79abfa247787e6adbd5ea34c (patch)
treebd9db168c57478f4f37c234eac4087c2d69a6445 /src/construct/thematic_break.rs
parent0bc099f8f8b6541a962e604b7ac25445a2a9252a (diff)
downloadmarkdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.tar.gz
markdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.tar.bz2
markdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.zip
Refactor code style
Diffstat (limited to '')
-rw-r--r--src/construct/thematic_break.rs19
1 files changed, 16 insertions, 3 deletions
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,
},
),