Use then() instead of ifs and Somes

main
Charlotte Som 2021-08-09 15:49:37 +01:00
parent bbf120f753
commit 4f4764705d
1 changed files with 3 additions and 12 deletions

View File

@ -45,13 +45,7 @@ pub fn parse(text: &'_ str) -> Vec<DiscordComponent<'_>> {
pub fn parse_token(text: &'_ str, is_line_start: bool) -> Option<(DiscordComponent<'_>, usize)> { pub fn parse_token(text: &'_ str, is_line_start: bool) -> Option<(DiscordComponent<'_>, usize)> {
parse_escaped_literal(text) parse_escaped_literal(text)
.or_else(|| { .or_else(|| is_line_start.then(|| parse_quotes(text)).flatten())
if is_line_start {
parse_quotes(text)
} else {
None
}
})
.or_else(|| parse_code_block(text)) .or_else(|| parse_code_block(text))
.or_else(|| parse_code(text)) .or_else(|| parse_code(text))
.or_else(|| parse_link(text)) .or_else(|| parse_link(text))
@ -79,9 +73,6 @@ pub fn parse_escaped_literal(text: &'_ str) -> Option<(DiscordComponent<'_>, usi
} }
pub fn parse_line_break(text: &'_ str) -> Option<(DiscordComponent<'_>, usize)> { pub fn parse_line_break(text: &'_ str) -> Option<(DiscordComponent<'_>, usize)> {
if text.starts_with('\n') { text.starts_with('\n')
return Some((DiscordComponent::LineBreak, 1)); .then(|| (DiscordComponent::LineBreak, 1))
}
None
} }