[librsvg] FontWeightSpec: simplify parser



commit 33d2c8dd6b89c6d6064b27a5330ee7beb2c4cefb
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jan 14 13:42:53 2020 -0600

    FontWeightSpec: simplify parser

 rsvg_internals/src/font_props.rs | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)
---
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index d61a9da3..1feab115 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -1,6 +1,6 @@
 //! CSS font properties.
 
-use cssparser::{BasicParseError, Parser};
+use cssparser::Parser;
 
 use crate::drawing_ctx::ViewParams;
 use crate::error::*;
@@ -114,21 +114,19 @@ impl Parse for FontWeightSpec {
             })
             .or_else(|_: ParseError| {
                 let loc = parser.current_source_location();
-                parser
-                    .expect_integer()
-                    .map_err(|e: BasicParseError| e.into())
-                    .and_then(|i| match i {
-                        100 => Ok(FontWeightSpec::W100),
-                        200 => Ok(FontWeightSpec::W200),
-                        300 => Ok(FontWeightSpec::W300),
-                        400 => Ok(FontWeightSpec::W400),
-                        500 => Ok(FontWeightSpec::W500),
-                        600 => Ok(FontWeightSpec::W600),
-                        700 => Ok(FontWeightSpec::W700),
-                        800 => Ok(FontWeightSpec::W800),
-                        900 => Ok(FontWeightSpec::W900),
-                        _ => Err(loc.new_custom_error(ValueErrorKind::parse_error("parse error"))),
-                    })
+                let i = parser.expect_integer()?;
+                match i {
+                    100 => Ok(FontWeightSpec::W100),
+                    200 => Ok(FontWeightSpec::W200),
+                    300 => Ok(FontWeightSpec::W300),
+                    400 => Ok(FontWeightSpec::W400),
+                    500 => Ok(FontWeightSpec::W500),
+                    600 => Ok(FontWeightSpec::W600),
+                    700 => Ok(FontWeightSpec::W700),
+                    800 => Ok(FontWeightSpec::W800),
+                    900 => Ok(FontWeightSpec::W900),
+                    _ => Err(loc.new_custom_error(ValueErrorKind::parse_error("parse error"))),
+                }
             })
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]