[librsvg] structure.rs: Use RsvgLength::check_nonnegative() instead of doing it by hand



commit e7be0cc58798157ce2703a5ddd4f979b20fd96f9
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Sep 4 12:42:04 2017 -0500

    structure.rs: Use RsvgLength::check_nonnegative() instead of doing it by hand

 rust/src/structure.rs |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)
---
diff --git a/rust/src/structure.rs b/rust/src/structure.rs
index 1b16c83..73c2a20 100644
--- a/rust/src/structure.rs
+++ b/rust/src/structure.rs
@@ -151,19 +151,13 @@ impl NodeTrait for NodeSvg {
             self.y.set (property_bag::length_or_default (pbag, "y", LengthDir::Vertical)?);
         }
 
-        let w = property_bag::length_or_value (pbag, "width", LengthDir::Horizontal, "100%")?;
-        if length_is_negative (&w) {
-            return Err (NodeError::value_error ("width", "Must not be negative"));
-        } else {
-            self.w.set (w);
-        }
+        self.w.set (property_bag::length_or_value (pbag, "width", LengthDir::Horizontal, "100%")
+                    .and_then (|l| l.check_nonnegative ()
+                               .map_err (|e| NodeError::attribute_error ("width", e)))?);
 
-        let h = property_bag::length_or_value (pbag, "height", LengthDir::Vertical, "100%")?;
-        if length_is_negative (&h) {
-            return Err (NodeError::value_error ("height", "Must not be negative"));
-        } else {
-            self.h.set (h);
-        }
+        self.h.set (property_bag::length_or_value (pbag, "height", LengthDir::Vertical, "100%")
+                    .and_then (|l| l.check_nonnegative ()
+                               .map_err (|e| NodeError::attribute_error ("height", e)))?);
 
         self.vbox.set (property_bag::parse_or_none (pbag, "viewBox")?);
 


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