[librsvg] NumberList: Don't use the Parse trait; implement similar methods directly



commit 1c2d3b8f605d9b82dfe5faff3757434d2de4e172
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Jan 21 19:58:54 2019 -0600

    NumberList: Don't use the Parse trait; implement similar methods directly
    
    NumberList::parse() and parse_str() are used in a couple of places,
    but we'll pass the NumberListLength argument directly, rather than
    relying on the Data associated type in Parse.

 rsvg_internals/src/number_list.rs | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/rsvg_internals/src/number_list.rs b/rsvg_internals/src/number_list.rs
index 73ab065d..1fb9f2fd 100644
--- a/rsvg_internals/src/number_list.rs
+++ b/rsvg_internals/src/number_list.rs
@@ -1,4 +1,4 @@
-use cssparser::Parser;
+use cssparser::{Parser, ParserInput};
 
 use parsers::{CssParserExt, Parse, ParseError};
 
@@ -17,11 +17,8 @@ pub enum NumberListError {
 #[derive(Debug, PartialEq)]
 pub struct NumberList(pub Vec<f64>);
 
-impl Parse for NumberList {
-    type Data = NumberListLength;
-    type Err = NumberListError;
-
-    fn parse(
+impl NumberList {
+    pub fn parse(
         parser: &mut Parser<'_, '_>,
         length: NumberListLength,
     ) -> Result<NumberList, NumberListError> {
@@ -68,6 +65,16 @@ impl Parse for NumberList {
 
         Ok(NumberList(v))
     }
+
+    pub fn parse_str(s: &str, length: NumberListLength) -> Result<NumberList, NumberListError> {
+        let mut input = ParserInput::new(s);
+        let mut parser = Parser::new(&mut input);
+
+        Self::parse(&mut parser, length).and_then(|r| {
+            // FIXME: parser.expect_exhausted()?;
+            Ok(r)
+        })
+    }
 }
 
 #[cfg(test)]


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