From bc39f16b4b94a7e93cf3fc73c764c3d0e60806b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 17 Sep 2018 00:53:37 +0000 Subject: [PATCH] style: Simplify CSSWideKeyword::parse. Differential Revision: https://phabricator.services.mozilla.com/D5972 --- .../style/properties/properties.mako.rs | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index c78bd863438..3ab358524ba 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -853,25 +853,22 @@ impl CSSWideKeyword { CSSWideKeyword::Unset => "unset", } } - - /// Takes the result of cssparser::Parser::expect_ident() and converts it - /// to a CSSWideKeyword. - pub fn from_ident<'i>(ident: &str) -> Option { - match_ignore_ascii_case! { ident, - // If modifying this set of keyword, also update values::CustomIdent::from_ident - "initial" => Some(CSSWideKeyword::Initial), - "inherit" => Some(CSSWideKeyword::Inherit), - "unset" => Some(CSSWideKeyword::Unset), - _ => None - } - } } impl CSSWideKeyword { fn parse(input: &mut Parser) -> Result { - let ident = input.expect_ident().map_err(|_| ())?.clone(); + let keyword = { + let ident = input.expect_ident().map_err(|_| ())?; + match_ignore_ascii_case! { ident, + // If modifying this set of keyword, also update values::CustomIdent::from_ident + "initial" => CSSWideKeyword::Initial, + "inherit" => CSSWideKeyword::Inherit, + "unset" => CSSWideKeyword::Unset, + _ => return Err(()), + } + }; input.expect_exhausted().map_err(|_| ())?; - CSSWideKeyword::from_ident(&ident).ok_or(()) + Ok(keyword) } }