From 7c3a85de4fe8851bbff7c477237ed88954b9f9c5 Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Tue, 1 Aug 2023 04:33:36 +0200 Subject: parser: remove panicking `From<&str> for Whitespace` --- askama_parser/src/node.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index b9685e8..4a0fa30 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -699,18 +699,11 @@ pub enum Whitespace { impl Whitespace { fn parse(i: &str) -> IResult<&str, Self> { - alt((char('-'), char('+'), char('~')))(i).map(|(s, r)| (s, Self::from(r))) - } -} - -impl From for Whitespace { - fn from(c: char) -> Self { - match c { - '+' => Self::Preserve, - '-' => Self::Suppress, - '~' => Self::Minimize, - _ => panic!("unsupported `Whitespace` conversion"), - } + alt(( + value(Self::Preserve, char('+')), + value(Self::Suppress, char('-')), + value(Self::Minimize, char('~')), + ))(i) } } -- cgit