From f9be622eeb2b1cb3c2419f3c4555748db7371815 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Fri, 26 Jun 2020 05:12:28 -0400 Subject: [PATCH] put errors in Box --- src/atrule/kind.rs | 4 ++-- src/error.rs | 34 +++++++++++++++++----------------- src/lib.rs | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/atrule/kind.rs b/src/atrule/kind.rs index 11d64f7..6ee8538 100644 --- a/src/atrule/kind.rs +++ b/src/atrule/kind.rs @@ -70,8 +70,8 @@ pub enum AtRuleKind { } impl TryFrom<&Spanned> for AtRuleKind { - type Error = SassError; - fn try_from(c: &Spanned) -> Result { + type Error = Box; + fn try_from(c: &Spanned) -> Result> { Ok(match c.node.as_str() { "use" => Self::Use, "forward" => Self::Forward, diff --git a/src/error.rs b/src/error.rs index b05632c..c87b875 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,7 @@ use std::{ use codemap::{Span, SpanLoc}; -pub type SassResult = Result; +pub type SassResult = Result>; #[derive(Debug)] pub struct SassError { @@ -78,42 +78,42 @@ impl Display for SassError { } } -impl From for SassError { +impl From for Box { #[inline] - fn from(error: io::Error) -> Self { - SassError { + fn from(error: io::Error) -> Box { + Box::new(SassError { kind: SassErrorKind::IoError(error), - } + }) } } -impl From for SassError { +impl From for Box { #[inline] - fn from(error: FromUtf8Error) -> Self { - SassError { + fn from(error: FromUtf8Error) -> Box { + Box::new(SassError { kind: SassErrorKind::FromUtf8Error(format!( "Invalid UTF-8 character \"\\x{:X?}\"", error.as_bytes()[0] )), - } + }) } } -impl From<(&str, Span)> for SassError { +impl From<(&str, Span)> for Box { #[inline] - fn from(error: (&str, Span)) -> SassError { - SassError { + fn from(error: (&str, Span)) -> Box { + Box::new(SassError { kind: SassErrorKind::Raw(error.0.to_owned(), error.1), - } + }) } } -impl From<(String, Span)> for SassError { +impl From<(String, Span)> for Box { #[inline] - fn from(error: (String, Span)) -> SassError { - SassError { + fn from(error: (String, Span)) -> Box { + Box::new(SassError { kind: SassErrorKind::Raw(error.0, error.1), - } + }) } } diff --git a/src/lib.rs b/src/lib.rs index fabe05b..45d2d99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,9 +126,9 @@ mod unit; mod utils; mod value; -fn raw_to_parse_error(map: &CodeMap, err: Error) -> Error { +fn raw_to_parse_error(map: &CodeMap, err: Box) -> Box { let (message, span) = err.raw(); - Error::from_loc(message, map.look_up_span(span)) + Box::new(Error::from_loc(message, map.look_up_span(span))) } /// Write CSS to `buf`, constructed from a path