Skip to content

Commit

Permalink
Implement into_owned for parser errors
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Apr 24, 2023
1 parent 4028d4d commit c3f64c2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/error.rs
Expand Up @@ -66,6 +66,7 @@ impl fmt::Display for ErrorLocation {

/// A parser error.
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "into_owned", derive(lightningcss_derive::IntoOwned))]
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type", content = "value"))]
pub enum ParserError<'i> {
Expand Down Expand Up @@ -156,6 +157,14 @@ impl<'i> Error<ParserError<'i>> {
}),
}
}

/// Consumes the value and returns an owned clone.
pub fn into_owned<'x>(self) -> Error<ParserError<'static>> {
Error {
kind: self.kind.into_owned(),
loc: self.loc,
}
}
}

impl<'i> From<SelectorParseErrorKind<'i>> for ParserError<'i> {
Expand All @@ -174,6 +183,7 @@ impl<'i> ParserError<'i> {

/// A selector parsing error.
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "into_owned", derive(lightningcss_derive::IntoOwned))]
#[cfg_attr(any(feature = "serde", feature = "nodejs"), derive(Serialize))]
#[cfg_attr(any(feature = "serde", feature = "nodejs"), serde(tag = "type", content = "value"))]
pub enum SelectorError<'i> {
Expand Down

0 comments on commit c3f64c2

Please sign in to comment.