[librsvg: 41/43] Remove the Parse and ParseValue traits



commit 024e1866613b75aaf8d87782224777ba65e113e5
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Dec 20 19:37:39 2019 -0600

    Remove the Parse and ParseValue traits
    
    Next, we'll rename the ToParseError ones back.

 rsvg_internals/src/parsers.rs | 35 ++++-------------------------------
 1 file changed, 4 insertions(+), 31 deletions(-)
---
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index d5f63127..b8891145 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -8,21 +8,21 @@ use std::str;
 use crate::error::*;
 
 /// Trait to parse values using `cssparser::Parser`.
-pub trait Parse: Sized {
+pub trait ParseToParseError: Sized {
     /// Parses a value out of the `parser`.
     ///
     /// All value types should implement this for composability.
-    fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind>;
+    fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, CssParseError<'i>>;
 
     /// 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, ValueErrorKind> {
+    fn parse_str_to_parse_error<'i>(s: &'i str) -> Result<Self, CssParseError<'i>> {
         let mut input = ParserInput::new(s);
         let mut parser = Parser::new(&mut input);
 
-        Self::parse(&mut parser).and_then(|r| {
+        Self::parse_to_parse_error(&mut parser).and_then(|r| {
             // FIXME: parser.expect_exhausted()?;
             Ok(r)
         })
@@ -42,20 +42,6 @@ pub fn finite_f32(n: f32) -> Result<f32, ValueErrorKind> {
     }
 }
 
-pub trait ParseValue<T: Parse> {
-    /// Parses a `value` string into a type `T`.
-    fn parse(&self, value: &str) -> Result<T, NodeError>;
-}
-
-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);
-
-        T::parse(&mut parser).attribute(self.clone())
-    }
-}
-
 pub trait ParseValueToParseError<T: ParseToParseError> {
     /// Parses a `value` string into a type `T`.
     fn parse_to_parse_error(&self, value: &str) -> Result<T, NodeError>;
@@ -90,19 +76,6 @@ impl<T: ParseToParseError> ParseValueToParseError<T> for QualName {
     }
 }
 
-pub trait ParseToParseError: Sized {
-    fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, CssParseError<'i>>;
-    fn parse_str_to_parse_error<'i>(s: &'i str) -> Result<Self, CssParseError<'i>> {
-        let mut input = ParserInput::new(s);
-        let mut parser = Parser::new(&mut input);
-
-        Self::parse_to_parse_error(&mut parser).and_then(|r| {
-            // FIXME: parser.expect_exhausted()?;
-            Ok(r)
-        })
-    }
-}
-
 impl ParseToParseError for f64 {
     fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, CssParseError<'i>> {
         let loc = parser.current_source_location();


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