[librsvg: 9/10] FilterFunction::parse - make it more obvious how to add new filter functions there




commit 870684a03149720da7592e1b13a487a5c7fee926
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Apr 28 18:38:31 2021 -0500

    FilterFunction::parse - make it more obvious how to add new filter functions there

 src/filter_func.rs | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
---
diff --git a/src/filter_func.rs b/src/filter_func.rs
index 2ede5abb..1698043b 100644
--- a/src/filter_func.rs
+++ b/src/filter_func.rs
@@ -56,11 +56,7 @@ fn parse_blur<'i>(parser: &mut Parser<'i, '_>) -> Result<FilterFunction, ParseEr
 }
 
 impl Blur {
-    fn to_filter_spec(
-        &self,
-        values: &ComputedValues,
-        params: &ViewParams,
-    ) -> FilterSpec {
+    fn to_filter_spec(&self, values: &ComputedValues, params: &ViewParams) -> FilterSpec {
         // The 0.0 default is from the spec
         let std_dev = self
             .std_deviation
@@ -89,11 +85,11 @@ impl Parse for FilterFunction {
     fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, crate::error::ParseError<'i>> {
         let loc = parser.current_source_location();
 
-        parser
-            .try_parse(|p| parse_function(p, "blur", parse_blur))
-            .or_else(|_| {
-                Err(loc.new_custom_error(ValueErrorKind::parse_error("expected filter function")))
-            })
+        if let Ok(func) = parser.try_parse(|p| parse_function(p, "blur", parse_blur)) {
+            return Ok(func);
+        }
+
+        return Err(loc.new_custom_error(ValueErrorKind::parse_error("expected filter function")));
     }
 }
 


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