[librsvg: 12/18] trait Parse - remove the Err associated type



commit 9d465859488cfea52358b234d0b8b491953899c6
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Dec 6 18:00:52 2019 -0600

    trait Parse - remove the Err associated type
    
    Make it ValueErrorKind unconditionally everywhere.

 rsvg_internals/src/angle.rs             |  2 --
 rsvg_internals/src/aspect_ratio.rs      |  2 --
 rsvg_internals/src/color.rs             |  4 ----
 rsvg_internals/src/coord_units.rs       |  4 ----
 rsvg_internals/src/dasharray.rs         |  2 --
 rsvg_internals/src/filters/composite.rs |  4 +---
 rsvg_internals/src/font_props.rs        |  8 --------
 rsvg_internals/src/gradient.rs          |  2 --
 rsvg_internals/src/iri.rs               |  2 --
 rsvg_internals/src/length.rs            |  2 --
 rsvg_internals/src/marker.rs            |  4 ----
 rsvg_internals/src/paint_server.rs      |  2 --
 rsvg_internals/src/parsers.rs           | 13 ++++---------
 rsvg_internals/src/properties.rs        |  2 +-
 rsvg_internals/src/property_defs.rs     |  6 ------
 rsvg_internals/src/property_macros.rs   |  6 ------
 rsvg_internals/src/shapes.rs            |  2 --
 rsvg_internals/src/style.rs             |  2 --
 rsvg_internals/src/transform.rs         |  2 --
 rsvg_internals/src/unit_interval.rs     |  2 --
 rsvg_internals/src/viewbox.rs           |  2 --
 21 files changed, 6 insertions(+), 69 deletions(-)
---
diff --git a/rsvg_internals/src/angle.rs b/rsvg_internals/src/angle.rs
index 4fc10d35..d91db743 100644
--- a/rsvg_internals/src/angle.rs
+++ b/rsvg_internals/src/angle.rs
@@ -60,8 +60,6 @@ impl Angle {
 // angle ::= number ("deg" | "grad" | "rad")?
 //
 impl Parse for Angle {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<Angle, ValueErrorKind> {
         let angle = {
             let token = parser
diff --git a/rsvg_internals/src/aspect_ratio.rs b/rsvg_internals/src/aspect_ratio.rs
index d4475aef..43a4851f 100644
--- a/rsvg_internals/src/aspect_ratio.rs
+++ b/rsvg_internals/src/aspect_ratio.rs
@@ -219,8 +219,6 @@ fn parse_fit_mode(s: &str) -> Result<FitMode, ValueErrorKind> {
 }
 
 impl Parse for AspectRatio {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<AspectRatio, ValueErrorKind> {
         let defer = parser
             .try_parse(|p| p.expect_ident_matching("defer"))
diff --git a/rsvg_internals/src/color.rs b/rsvg_internals/src/color.rs
index 350f1c02..75780792 100644
--- a/rsvg_internals/src/color.rs
+++ b/rsvg_internals/src/color.rs
@@ -9,8 +9,6 @@ use crate::util::utf8_cstr;
 pub use cssparser::Color;
 
 impl Parse for cssparser::Color {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<cssparser::Color, ValueErrorKind> {
         cssparser::Color::parse(parser)
             .map_err(|_| ValueErrorKind::Parse(ParseError::new("invalid syntax for color")))
@@ -18,8 +16,6 @@ impl Parse for cssparser::Color {
 }
 
 impl Parse for cssparser::RGBA {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<cssparser::RGBA, ValueErrorKind> {
         match cssparser::Color::parse(parser) {
             Ok(cssparser::Color::RGBA(rgba)) => Ok(rgba),
diff --git a/rsvg_internals/src/coord_units.rs b/rsvg_internals/src/coord_units.rs
index 31eed75e..b550ceb3 100644
--- a/rsvg_internals/src/coord_units.rs
+++ b/rsvg_internals/src/coord_units.rs
@@ -13,8 +13,6 @@ pub enum CoordUnits {
 }
 
 impl Parse for CoordUnits {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<CoordUnits, ValueErrorKind> {
         let loc = parser.current_source_location();
 
@@ -64,8 +62,6 @@ macro_rules! coord_units {
         }
 
         impl $crate::parsers::Parse for $name {
-            type Err = $crate::error::ValueErrorKind;
-
             fn parse(
                 parser: &mut ::cssparser::Parser<'_, '_>,
             ) -> Result<Self, $crate::error::ValueErrorKind> {
diff --git a/rsvg_internals/src/dasharray.rs b/rsvg_internals/src/dasharray.rs
index 6e55e889..8fe515a5 100644
--- a/rsvg_internals/src/dasharray.rs
+++ b/rsvg_internals/src/dasharray.rs
@@ -17,8 +17,6 @@ impl Default for Dasharray {
 }
 
 impl Parse for Dasharray {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<Dasharray, ValueErrorKind> {
         if parser
             .try_parse(|p| p.expect_ident_matching("none"))
diff --git a/rsvg_internals/src/filters/composite.rs b/rsvg_internals/src/filters/composite.rs
index 4f30ca5c..1fff2231 100644
--- a/rsvg_internals/src/filters/composite.rs
+++ b/rsvg_internals/src/filters/composite.rs
@@ -212,9 +212,7 @@ impl FilterEffect for FeComposite {
 }
 
 impl Parse for Operator {
-    type Err = ValueErrorKind;
-
-    fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, Self::Err> {
+    fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind> {
         let loc = parser.current_source_location();
 
         parser
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index 616c9499..c810f5cc 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -59,8 +59,6 @@ impl FontSizeSpec {
 }
 
 impl Parse for FontSizeSpec {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<FontSizeSpec, crate::error::ValueErrorKind> {
         let parser_state = parser.state();
 
@@ -118,8 +116,6 @@ pub enum FontWeightSpec {
 }
 
 impl Parse for FontWeightSpec {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<FontWeightSpec, crate::error::ValueErrorKind> {
         if let Ok(r) = parser.try_parse(|p| {
             p.expect_ident()
@@ -190,8 +186,6 @@ impl LetterSpacingSpec {
 }
 
 impl Parse for LetterSpacingSpec {
-    type Err = ValueErrorKind;
-
     fn parse(
         parser: &mut Parser<'_, '_>,
     ) -> Result<LetterSpacingSpec, crate::error::ValueErrorKind> {
@@ -228,8 +222,6 @@ impl Parse for LetterSpacingSpec {
 pub struct SingleFontFamily(pub String);
 
 impl Parse for SingleFontFamily {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<SingleFontFamily, ValueErrorKind> {
         parse_single_font_family(parser)
             .map_err(|_| ValueErrorKind::from(ParseError::new("expected font family")))
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index e30ad815..d4021baa 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -43,8 +43,6 @@ enum SpreadMethod {
 }
 
 impl Parse for SpreadMethod {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<SpreadMethod, ValueErrorKind> {
         let loc = parser.current_source_location();
 
diff --git a/rsvg_internals/src/iri.rs b/rsvg_internals/src/iri.rs
index 9b6b8268..b1c1ae3b 100644
--- a/rsvg_internals/src/iri.rs
+++ b/rsvg_internals/src/iri.rs
@@ -34,8 +34,6 @@ impl IRI {
 }
 
 impl Parse for IRI {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<IRI, ValueErrorKind> {
         if parser
             .try_parse(|i| i.expect_ident_matching("none"))
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index 0ba865d9..f0bcfd4c 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -235,8 +235,6 @@ fn make_err() -> ValueErrorKind {
 }
 
 impl<N: Normalize> Parse for Length<N> {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<Length<N>, ValueErrorKind> {
         let length = {
             let token = parser.next().map_err(|_| {
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 1dbc41b7..4a0651de 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -35,8 +35,6 @@ impl Default for MarkerUnits {
 }
 
 impl Parse for MarkerUnits {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<MarkerUnits, ValueErrorKind> {
         let loc = parser.current_source_location();
 
@@ -73,8 +71,6 @@ impl Default for MarkerOrient {
 }
 
 impl Parse for MarkerOrient {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<MarkerOrient, ValueErrorKind> {
         if parser
             .try_parse(|p| p.expect_ident_matching("auto"))
diff --git a/rsvg_internals/src/paint_server.rs b/rsvg_internals/src/paint_server.rs
index cfc76089..54d12c59 100644
--- a/rsvg_internals/src/paint_server.rs
+++ b/rsvg_internals/src/paint_server.rs
@@ -20,8 +20,6 @@ pub enum PaintServer {
 }
 
 impl Parse for PaintServer {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<PaintServer, ValueErrorKind> {
         if parser
             .try_parse(|i| i.expect_ident_matching("none"))
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index 71bb9848..9f5577a9 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -36,19 +36,16 @@ impl<'a> From<BasicParseError<'a>> for ParseError {
 
 /// Trait to parse values using `cssparser::Parser`.
 pub trait Parse: Sized {
-    /// Error type for parse errors.
-    type Err;
-
     /// Parses a value out of the `parser`.
     ///
     /// All value types should implement this for composability.
-    fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, Self::Err>;
+    fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind>;
 
     /// Convenience function to parse a value out of a `&str`.
     ///
     /// This is useful mostly for tests which want to avoid creating a
     /// `cssparser::Parser` by hand.
-    fn parse_str(s: &str) -> Result<Self, Self::Err> {
+    fn parse_str(s: &str) -> Result<Self, ValueErrorKind> {
         let mut input = ParserInput::new(s);
         let mut parser = Parser::new(&mut input);
 
@@ -86,7 +83,7 @@ pub fn finite_f32(n: f32) -> Result<f32, ValueErrorKind> {
     }
 }
 
-pub trait ParseValue<T: Parse<Err = ValueErrorKind>> {
+pub trait ParseValue<T: Parse> {
     /// Parses a `value` string into a type `T`.
     fn parse(&self, value: &str) -> Result<T, NodeError>;
 
@@ -98,7 +95,7 @@ pub trait ParseValue<T: Parse<Err = ValueErrorKind>> {
     ) -> Result<T, NodeError>;
 }
 
-impl<T: Parse<Err = ValueErrorKind>> ParseValue<T> for QualName {
+impl<T: Parse> ParseValue<T> for QualName {
     fn parse(&self, value: &str) -> Result<T, NodeError> {
         let mut input = ParserInput::new(value);
         let mut parser = Parser::new(&mut input);
@@ -121,8 +118,6 @@ impl<T: Parse<Err = ValueErrorKind>> ParseValue<T> for QualName {
 }
 
 impl Parse for f64 {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<f64, ValueErrorKind> {
         Ok(f64::from(parser.expect_finite_number().map_err(|_| {
             ValueErrorKind::Parse(ParseError::new("expected number"))
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 33723b42..3a7bf257 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -615,7 +615,7 @@ impl SpecifiedValues {
 }
 
 // Parses the value for the type `T` of the property out of the Parser, including `inherit` values.
-fn parse_input<T>(input: &mut Parser) -> Result<SpecifiedValue<T>, <T as Parse>::Err>
+fn parse_input<T>(input: &mut Parser) -> Result<SpecifiedValue<T>, ValueErrorKind>
 where
     T: Property<ComputedValues> + Clone + Default + Parse,
 {
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index 7df5c0aa..e5a0cc0e 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -40,8 +40,6 @@ make_property!(
     },
     parse_impl: {
         impl Parse for BaselineShift {
-            type Err = ValueErrorKind;
-
             // These values come from Inkscape's SP_CSS_BASELINE_SHIFT_(SUB/SUPER/BASELINE);
             // see sp_style_merge_baseline_shift_from_parent()
             fn parse(parser: &mut Parser<'_, '_>) -> Result<BaselineShift, crate::error::ValueErrorKind> {
@@ -553,8 +551,6 @@ make_property!(
 
     parse_impl: {
         impl Parse for TextDecoration {
-            type Err = ValueErrorKind;
-
             fn parse(parser: &mut Parser<'_, '_>) -> Result<TextDecoration, ValueErrorKind> {
                 let mut overline = false;
                 let mut underline = false;
@@ -711,8 +707,6 @@ make_property!(
     newtype: String,
     parse_impl: {
         impl Parse for XmlLang {
-            type Err = ValueErrorKind;
-
             fn parse(
                 parser: &mut Parser<'_, '_>,
             ) -> Result<XmlLang, ValueErrorKind> {
diff --git a/rsvg_internals/src/property_macros.rs b/rsvg_internals/src/property_macros.rs
index 547fd069..a499cafb 100644
--- a/rsvg_internals/src/property_macros.rs
+++ b/rsvg_internals/src/property_macros.rs
@@ -44,8 +44,6 @@ macro_rules! make_property {
         impl_property!($computed_values_type, $name, $inherits_automatically);
 
         impl crate::parsers::Parse for $name {
-            type Err = crate::error::ValueErrorKind;
-
             fn parse(parser: &mut ::cssparser::Parser<'_, '_>) -> Result<$name, 
crate::error::ValueErrorKind> {
                 let loc = parser.current_source_location();
 
@@ -83,8 +81,6 @@ macro_rules! make_property {
         impl_property!($computed_values_type, $name, $inherits_automatically);
 
         impl crate::parsers::Parse for $name {
-            type Err = crate::error::ValueErrorKind;
-
             fn parse(parser: &mut ::cssparser::Parser<'_, '_>) -> Result<$name, 
crate::error::ValueErrorKind> {
                 Ok($name(<$type as crate::parsers::Parse>::parse(parser)?))
             }
@@ -105,8 +101,6 @@ macro_rules! make_property {
         $prop
 
         impl crate::parsers::Parse for $name {
-            type Err = crate::error::ValueErrorKind;
-
             fn parse(parser: &mut ::cssparser::Parser<'_, '_>) -> Result<$name, 
crate::error::ValueErrorKind> {
                 Ok($name(<$type as crate::parsers::Parse>::parse(parser)?))
             }
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index 8443c25a..9352cd61 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -159,8 +159,6 @@ impl Deref for Points {
 // Parse a list-of-points as for polyline and polygon elements
 // https://www.w3.org/TR/SVG/shapes.html#PointsBNF
 impl Parse for Points {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<Points, ValueErrorKind> {
         let mut v = Vec::new();
 
diff --git a/rsvg_internals/src/style.rs b/rsvg_internals/src/style.rs
index e128349f..ca6b3736 100644
--- a/rsvg_internals/src/style.rs
+++ b/rsvg_internals/src/style.rs
@@ -18,8 +18,6 @@ pub enum StyleType {
 }
 
 impl Parse for StyleType {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<StyleType, ValueErrorKind> {
         parser
             .expect_ident_matching("text/css")
diff --git a/rsvg_internals/src/transform.rs b/rsvg_internals/src/transform.rs
index 89298307..0d3351d7 100644
--- a/rsvg_internals/src/transform.rs
+++ b/rsvg_internals/src/transform.rs
@@ -8,8 +8,6 @@ use crate::error::*;
 use crate::parsers::{finite_f32, CssParserExt, Parse, ParseError};
 
 impl Parse for cairo::Matrix {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<cairo::Matrix, ValueErrorKind> {
         let matrix = parse_transform_list(parser)?;
 
diff --git a/rsvg_internals/src/unit_interval.rs b/rsvg_internals/src/unit_interval.rs
index cd9d4491..897866ff 100644
--- a/rsvg_internals/src/unit_interval.rs
+++ b/rsvg_internals/src/unit_interval.rs
@@ -14,8 +14,6 @@ impl UnitInterval {
 }
 
 impl Parse for UnitInterval {
-    type Err = ValueErrorKind;
-
     fn parse(parser: &mut Parser<'_, '_>) -> Result<UnitInterval, ValueErrorKind> {
         let x = f64::from(
             parser
diff --git a/rsvg_internals/src/viewbox.rs b/rsvg_internals/src/viewbox.rs
index 5826a99e..1f48c97d 100644
--- a/rsvg_internals/src/viewbox.rs
+++ b/rsvg_internals/src/viewbox.rs
@@ -29,8 +29,6 @@ impl ViewBox {
 }
 
 impl Parse for ViewBox {
-    type Err = ValueErrorKind;
-
     // Parse a viewBox attribute
     // https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
     //


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