[librsvg: 34/43] Convert CoordUnits to CssParseError



commit a5ed474091a1a6fbe3bf227134f056fc0a494b50
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Dec 20 18:42:26 2019 -0600

    Convert CoordUnits to CssParseError

 rsvg_internals/src/clip_path.rs   |  4 ++--
 rsvg_internals/src/coord_units.rs | 30 +++++++++++++++---------------
 rsvg_internals/src/filter.rs      |  6 +++---
 rsvg_internals/src/gradient.rs    |  2 +-
 rsvg_internals/src/mask.rs        |  6 +++---
 rsvg_internals/src/pattern.rs     |  4 ++--
 6 files changed, 26 insertions(+), 26 deletions(-)
---
diff --git a/rsvg_internals/src/clip_path.rs b/rsvg_internals/src/clip_path.rs
index 97a512cf..0e332d89 100644
--- a/rsvg_internals/src/clip_path.rs
+++ b/rsvg_internals/src/clip_path.rs
@@ -8,7 +8,7 @@ use crate::coord_units::CoordUnits;
 use crate::drawing_ctx::DrawingCtx;
 use crate::error::RenderingError;
 use crate::node::{CascadedValues, NodeDraw, NodeResult, NodeTrait, RsvgNode};
-use crate::parsers::ParseValue;
+use crate::parsers::ParseValueToParseError;
 use crate::property_bag::PropertyBag;
 
 coord_units!(ClipPathUnits, CoordUnits::UserSpaceOnUse);
@@ -73,7 +73,7 @@ impl NodeTrait for ClipPath {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "clipPathUnits") => self.units = attr.parse(value)?,
+                expanded_name!(svg "clipPathUnits") => self.units = attr.parse_to_parse_error(value)?,
                 _ => (),
             }
         }
diff --git a/rsvg_internals/src/coord_units.rs b/rsvg_internals/src/coord_units.rs
index 0b19b68c..765f5d8f 100644
--- a/rsvg_internals/src/coord_units.rs
+++ b/rsvg_internals/src/coord_units.rs
@@ -1,9 +1,9 @@
 //! `userSpaceOnUse` or `objectBoundingBox` values.
 
-use cssparser::{BasicParseError, Parser};
+use cssparser::Parser;
 
 use crate::error::*;
-use crate::parsers::Parse;
+use crate::parsers::ParseToParseError;
 
 /// Defines the units to be used for things that can consider a
 /// coordinate system in terms of the current transformation, or in
@@ -14,13 +14,13 @@ pub enum CoordUnits {
     ObjectBoundingBox,
 }
 
-impl Parse for CoordUnits {
-    fn parse(parser: &mut Parser<'_, '_>) -> Result<CoordUnits, ValueErrorKind> {
-        parse_identifiers!(
+impl ParseToParseError for CoordUnits {
+    fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, CssParseError<'i>> {
+        Ok(parse_identifiers!(
             parser,
             "userSpaceOnUse" => CoordUnits::UserSpaceOnUse,
             "objectBoundingBox" => CoordUnits::ObjectBoundingBox,
-        ).map_err(|_: BasicParseError| ValueErrorKind::parse_error("parse error"))
+        )?)
     }
 }
 
@@ -50,11 +50,11 @@ macro_rules! coord_units {
             }
         }
 
-        impl $crate::parsers::Parse for $name {
-            fn parse(
-                parser: &mut ::cssparser::Parser<'_, '_>,
-            ) -> Result<Self, $crate::error::ValueErrorKind> {
-                Ok($name($crate::coord_units::CoordUnits::parse(parser)?))
+        impl $crate::parsers::ParseToParseError for $name {
+            fn parse_to_parse_error<'i>(
+                parser: &mut ::cssparser::Parser<'i, '_>,
+            ) -> Result<Self, $crate::error::CssParseError<'i>> {
+                Ok($name($crate::coord_units::CoordUnits::parse_to_parse_error(parser)?))
             }
         }
     };
@@ -68,18 +68,18 @@ mod tests {
 
     #[test]
     fn parsing_invalid_strings_yields_error() {
-        assert!(MyUnits::parse_str("").is_err());
-        assert!(MyUnits::parse_str("foo").is_err());
+        assert!(MyUnits::parse_str_to_parse_error("").is_err());
+        assert!(MyUnits::parse_str_to_parse_error("foo").is_err());
     }
 
     #[test]
     fn parses_paint_server_units() {
         assert_eq!(
-            MyUnits::parse_str("userSpaceOnUse"),
+            MyUnits::parse_str_to_parse_error("userSpaceOnUse"),
             Ok(MyUnits(CoordUnits::UserSpaceOnUse))
         );
         assert_eq!(
-            MyUnits::parse_str("objectBoundingBox"),
+            MyUnits::parse_str_to_parse_error("objectBoundingBox"),
             Ok(MyUnits(CoordUnits::ObjectBoundingBox))
         );
     }
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index e86b6bb3..c99669c5 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -9,7 +9,7 @@ use crate::drawing_ctx::DrawingCtx;
 use crate::error::ValueErrorKind;
 use crate::length::*;
 use crate::node::{NodeResult, NodeTrait, RsvgNode};
-use crate::parsers::{ParseToParseError, ParseValue, ParseValueToParseError};
+use crate::parsers::{ParseToParseError, ParseValueToParseError};
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::rect::Rect;
@@ -115,7 +115,7 @@ impl NodeTrait for Filter {
         // Parse filterUnits first as it affects x, y, width, height checks.
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "filterUnits") => self.filterunits = attr.parse(value)?,
+                expanded_name!(svg "filterUnits") => self.filterunits = attr.parse_to_parse_error(value)?,
                 _ => (),
             }
         }
@@ -179,7 +179,7 @@ impl NodeTrait for Filter {
                         check_units_vertical_and_ensure_nonnegative,
                     )?
                 }
-                expanded_name!(svg "primitiveUnits") => self.primitiveunits = attr.parse(value)?,
+                expanded_name!(svg "primitiveUnits") => self.primitiveunits = 
attr.parse_to_parse_error(value)?,
                 _ => (),
             }
         }
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index 669a97ff..808f9b52 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -548,7 +548,7 @@ impl Common {
     fn set_atts(&mut self, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "gradientUnits") => self.units = Some(attr.parse(value)?),
+                expanded_name!(svg "gradientUnits") => self.units = Some(attr.parse_to_parse_error(value)?),
                 expanded_name!(svg "gradientTransform") => self.affine = 
Some(attr.parse_to_parse_error(value)?),
                 expanded_name!(svg "spreadMethod") => self.spread = Some(attr.parse(value)?),
                 expanded_name!(xlink "href") => {
diff --git a/rsvg_internals/src/mask.rs b/rsvg_internals/src/mask.rs
index f5621a69..75a82167 100644
--- a/rsvg_internals/src/mask.rs
+++ b/rsvg_internals/src/mask.rs
@@ -9,7 +9,7 @@ use crate::drawing_ctx::{CompositingAffines, DrawingCtx};
 use crate::error::RenderingError;
 use crate::length::*;
 use crate::node::{CascadedValues, NodeDraw, NodeResult, NodeTrait, RsvgNode};
-use crate::parsers::{ParseToParseError, ParseValue, ParseValueToParseError};
+use crate::parsers::{ParseToParseError, ParseValueToParseError};
 use crate::property_bag::PropertyBag;
 use crate::property_defs::Opacity;
 use crate::rect::Rect;
@@ -146,8 +146,8 @@ impl NodeTrait for Mask {
                     self.height =
                         attr.parse_to_parse_error_and_validate(value, Length::<Vertical>::check_nonnegative)?
                 }
-                expanded_name!(svg "maskUnits") => self.units = attr.parse(value)?,
-                expanded_name!(svg "maskContentUnits") => self.content_units = attr.parse(value)?,
+                expanded_name!(svg "maskUnits") => self.units = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "maskContentUnits") => self.content_units = 
attr.parse_to_parse_error(value)?,
                 _ => (),
             }
         }
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index d7665d67..658cb740 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -120,9 +120,9 @@ impl NodeTrait for Pattern {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "patternUnits") => self.common.units = Some(attr.parse(value)?),
+                expanded_name!(svg "patternUnits") => self.common.units = 
Some(attr.parse_to_parse_error(value)?),
                 expanded_name!(svg "patternContentUnits") => {
-                    self.common.content_units = Some(attr.parse(value)?)
+                    self.common.content_units = Some(attr.parse_to_parse_error(value)?)
                 }
                 expanded_name!(svg "viewBox") => self.common.vbox = 
Some(Some(attr.parse_to_parse_error(value)?)),
                 expanded_name!(svg "preserveAspectRatio") => {


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