[librsvg: 14/18] Convert directly from cssparser::BasicParseError to our ValueErrorKind
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 14/18] Convert directly from cssparser::BasicParseError to our ValueErrorKind
- Date: Sat, 7 Dec 2019 02:39:12 +0000 (UTC)
commit e97580e02360771c699dd7fea85293f4089691ed
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Dec 6 18:33:58 2019 -0600
Convert directly from cssparser::BasicParseError to our ValueErrorKind
Instead of having an intermediate step through our ParseError.
rsvg_internals/src/error.rs | 14 ++++++++++++--
rsvg_internals/src/parsers.rs | 18 +-----------------
2 files changed, 13 insertions(+), 19 deletions(-)
---
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 2e25f0b0..5a76758d 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -2,7 +2,7 @@ use std::error::{self, Error};
use std::fmt;
use cairo;
-use cssparser::BasicParseError;
+use cssparser::{BasicParseError, BasicParseErrorKind};
use glib;
use markup5ever::QualName;
@@ -94,7 +94,17 @@ impl From<ParseError> for ValueErrorKind {
impl<'a> From<BasicParseError<'a>> for ValueErrorKind {
fn from(e: BasicParseError<'_>) -> ValueErrorKind {
- ValueErrorKind::from(ParseError::from(e))
+ let BasicParseError { kind, location: _ } = e;
+
+ let msg = match kind {
+ BasicParseErrorKind::UnexpectedToken(_) => "unexpected token",
+ BasicParseErrorKind::EndOfInput => "unexpected end of input",
+ BasicParseErrorKind::AtRuleInvalid(_) => "invalid @-rule",
+ BasicParseErrorKind::AtRuleBodyInvalid => "invalid @-rule body",
+ BasicParseErrorKind::QualifiedRuleInvalid => "invalid qualified rule",
+ };
+
+ ValueErrorKind::Parse(ParseError::new(msg))
}
}
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index 7c766161..d0053a7e 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -1,4 +1,4 @@
-use cssparser::{BasicParseError, BasicParseErrorKind, Parser, ParserInput, Token};
+use cssparser::{Parser, ParserInput, Token};
use markup5ever::QualName;
use std::str;
@@ -18,22 +18,6 @@ impl ParseError {
}
}
-impl<'a> From<BasicParseError<'a>> for ParseError {
- fn from(e: BasicParseError<'_>) -> ParseError {
- let BasicParseError { kind, location: _ } = e;
-
- let msg = match kind {
- BasicParseErrorKind::UnexpectedToken(_) => "unexpected token",
- BasicParseErrorKind::EndOfInput => "unexpected end of input",
- BasicParseErrorKind::AtRuleInvalid(_) => "invalid @-rule",
- BasicParseErrorKind::AtRuleBodyInvalid => "invalid @-rule body",
- BasicParseErrorKind::QualifiedRuleInvalid => "invalid qualified rule",
- };
-
- ParseError::new(msg)
- }
-}
-
/// Trait to parse values using `cssparser::Parser`.
pub trait Parse: Sized {
/// Parses a value out of the `parser`.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]