[librsvg] property_bag.rs: New functions length_or_value(), parse_or_value()



commit 7def4117c63f12ffef9d22be1639d5614a783815
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 22 16:27:24 2017 -0600

    property_bag.rs: New functions length_or_value(), parse_or_value()
    
    For callers who want to specify an explicit value instead of just using
    the default value for a type.

 rust/src/property_bag.rs |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/property_bag.rs b/rust/src/property_bag.rs
index 4b42b40..34761b0 100644
--- a/rust/src/property_bag.rs
+++ b/rust/src/property_bag.rs
@@ -48,6 +48,16 @@ pub fn length_or_default (pbag: *const RsvgPropertyBag, key: &'static str, lengt
     }
 }
 
+pub fn length_or_value (pbag: *const RsvgPropertyBag, key: &'static str, length_dir: LengthDir, length_str: 
&str) -> Result <RsvgLength, NodeError> {
+    let r = length_or_none (pbag, key, length_dir);
+
+    match r {
+        Ok (Some (v)) => Ok (v),
+        Ok (None)     => Ok (RsvgLength::parse (length_str, length_dir).unwrap ()),
+        Err (e)       => Err (e)
+    }
+}
+
 pub fn parse_or_none<T> (pbag: *const RsvgPropertyBag, key: &'static str) -> Result <Option<T>, NodeError>
     where T: Default + FromStr<Err = AttributeError>
 {
@@ -74,3 +84,15 @@ pub fn parse_or_default<T> (pbag: *const RsvgPropertyBag, key: &'static str) ->
         Err (e)       => Err (e)
     }
 }
+
+pub fn parse_or_value<T> (pbag: *const RsvgPropertyBag, key: &'static str, value: T) -> Result <T, NodeError>
+    where T: Default + FromStr<Err = AttributeError> + Copy
+{
+    let r = parse_or_none::<T> (pbag, key);
+
+    match r {
+        Ok (Some (v)) => Ok (v),
+        Ok (None)     => Ok (value),
+        Err (e)       => Err (e)
+    }
+}


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