[librsvg] property_bag.rs: Turn lookup_length() into length_or_default(); return errors
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] property_bag.rs: Turn lookup_length() into length_or_default(); return errors
- Date: Thu, 16 Mar 2017 05:17:00 +0000 (UTC)
commit 61c355cb22064e331228dc389500da447be6a900
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Mar 15 22:42:57 2017 -0600
property_bag.rs: Turn lookup_length() into length_or_default(); return errors
We used to return an RsvgLength with a default value in case of error.
Now we actually return a Result.
rust/src/marker.rs | 4 ++--
rust/src/property_bag.rs | 8 +++-----
rust/src/shapes.rs | 30 +++++++++++++++---------------
3 files changed, 20 insertions(+), 22 deletions(-)
---
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index 8a5ca00..42cc77b 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -215,8 +215,8 @@ impl NodeTrait for NodeMarker {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
self.units.set (property_bag::lookup_and_parse (pbag, "markerUnits"));
- self.ref_x.set (property_bag::lookup_length (pbag, "refX", LengthDir::Horizontal));
- self.ref_y.set (property_bag::lookup_length (pbag, "refY", LengthDir::Vertical));
+ self.ref_x.set (property_bag::length_or_default (pbag, "refX", LengthDir::Horizontal)?);
+ self.ref_y.set (property_bag::length_or_default (pbag, "refY", LengthDir::Vertical)?);
self.width.set (property_bag::lookup (pbag, "markerWidth").map_or (NodeMarker::get_default_size (),
|v| RsvgLength::parse (&v,
LengthDir::Horizontal).unwrap_or (NodeMarker::get_default_size ())));
diff --git a/rust/src/property_bag.rs b/rust/src/property_bag.rs
index 676db6d..d8801d8 100644
--- a/rust/src/property_bag.rs
+++ b/rust/src/property_bag.rs
@@ -44,15 +44,13 @@ pub fn lookup_and_parse<T: Default + FromStr> (pbag: *const RsvgPropertyBag, key
}
}
-pub fn lookup_length (pbag: *const RsvgPropertyBag, key: &str, length_dir: LengthDir) -> RsvgLength {
+pub fn length_or_default (pbag: *const RsvgPropertyBag, key: &'static str, length_dir: LengthDir) -> Result
<RsvgLength, NodeError> {
let value = lookup (pbag, key);
if let Some (v) = value {
-
- // FIXME: Error is discarded here. Figure out a way to propagate it upstream.
- RsvgLength::parse (&v, length_dir).unwrap_or (RsvgLength::default ())
+ RsvgLength::parse (&v, length_dir).map_err (|e| NodeError::attribute_error (key, e))
} else {
- RsvgLength::default ()
+ Ok (RsvgLength::default ())
}
}
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 1e9f4d0..e960f20 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -200,10 +200,10 @@ impl NodeLine {
impl NodeTrait for NodeLine {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
- self.x1.set (property_bag::lookup_length (pbag, "x1", LengthDir::Horizontal));
- self.y1.set (property_bag::lookup_length (pbag, "y1", LengthDir::Vertical));
- self.x2.set (property_bag::lookup_length (pbag, "x2", LengthDir::Horizontal));
- self.y2.set (property_bag::lookup_length (pbag, "y2", LengthDir::Vertical));
+ self.x1.set (property_bag::length_or_default (pbag, "x1", LengthDir::Horizontal)?);
+ self.y1.set (property_bag::length_or_default (pbag, "y1", LengthDir::Vertical)?);
+ self.x2.set (property_bag::length_or_default (pbag, "x2", LengthDir::Horizontal)?);
+ self.y2.set (property_bag::length_or_default (pbag, "y2", LengthDir::Vertical)?);
Ok (())
}
@@ -257,10 +257,10 @@ impl NodeRect {
impl NodeTrait for NodeRect {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
- self.x.set (property_bag::lookup_length (pbag, "x", LengthDir::Horizontal));
- self.y.set (property_bag::lookup_length (pbag, "y", LengthDir::Vertical));
- self.w.set (property_bag::lookup_length (pbag, "width", LengthDir::Horizontal));
- self.h.set (property_bag::lookup_length (pbag, "height", LengthDir::Vertical));
+ self.x.set (property_bag::length_or_default (pbag, "x", LengthDir::Horizontal)?);
+ self.y.set (property_bag::length_or_default (pbag, "y", LengthDir::Vertical)?);
+ self.w.set (property_bag::length_or_default (pbag, "width", LengthDir::Horizontal)?);
+ self.h.set (property_bag::length_or_default (pbag, "height", LengthDir::Vertical)?);
let v = property_bag::lookup (pbag, "rx");
if let Some (val) = v {
@@ -445,9 +445,9 @@ impl NodeCircle {
impl NodeTrait for NodeCircle {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
- self.cx.set (property_bag::lookup_length (pbag, "cx", LengthDir::Horizontal));
- self.cy.set (property_bag::lookup_length (pbag, "cy", LengthDir::Vertical));
- self.r.set (property_bag::lookup_length (pbag, "r", LengthDir::Both));
+ self.cx.set (property_bag::length_or_default (pbag, "cx", LengthDir::Horizontal)?);
+ self.cy.set (property_bag::length_or_default (pbag, "cy", LengthDir::Vertical)?);
+ self.r.set (property_bag::length_or_default (pbag, "r", LengthDir::Both)?);
Ok (())
}
@@ -487,10 +487,10 @@ impl NodeEllipse {
impl NodeTrait for NodeEllipse {
fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
- self.cx.set (property_bag::lookup_length (pbag, "cx", LengthDir::Horizontal));
- self.cy.set (property_bag::lookup_length (pbag, "cy", LengthDir::Vertical));
- self.rx.set (property_bag::lookup_length (pbag, "rx", LengthDir::Horizontal));
- self.ry.set (property_bag::lookup_length (pbag, "ry", LengthDir::Vertical));
+ self.cx.set (property_bag::length_or_default (pbag, "cx", LengthDir::Horizontal)?);
+ self.cy.set (property_bag::length_or_default (pbag, "cy", LengthDir::Vertical)?);
+ self.rx.set (property_bag::length_or_default (pbag, "rx", LengthDir::Horizontal)?);
+ self.ry.set (property_bag::length_or_default (pbag, "ry", LengthDir::Vertical)?);
Ok (())
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]