[librsvg: 1/43] properties.rs: Add a helper parse_input_to_parse_error to convert each parser



commit 832cca5d0683ab922dd3bfed4b931b53f770fc09
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Dec 19 18:02:55 2019 -0600

    properties.rs: Add a helper parse_input_to_parse_error to convert each parser

 rsvg_internals/src/properties.rs | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index ae8a0338..51045bfb 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -6,7 +6,7 @@ use std::collections::HashSet;
 
 use crate::css::{DeclParser, Declaration};
 use crate::error::*;
-use crate::parsers::Parse;
+use crate::parsers::{Parse, ParseToParseError};
 use crate::property_bag::PropertyBag;
 use crate::property_defs::*;
 use crate::property_macros::Property;
@@ -630,3 +630,18 @@ where
         Parse::parse(input).map(SpecifiedValue::Specified)
     }
 }
+
+// Parses the value for the type `T` of the property out of the Parser, including `inherit` values.
+fn parse_input_to_parse_error<'i, T>(input: &mut Parser<'i, '_>) -> Result<SpecifiedValue<T>, ParseError<'i>>
+where
+    T: Property<ComputedValues> + Clone + Default + ParseToParseError,
+{
+    if input
+        .try_parse(|p| p.expect_ident_matching("inherit"))
+        .is_ok()
+    {
+        Ok(SpecifiedValue::Inherit)
+    } else {
+        ParseToParseError::parse_to_parse_error(input).map(SpecifiedValue::Specified)
+    }
+}


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