Skip to content

Commit 5e332c0

Browse files
authored
Merge pull request #84 from rusty-ecma/fix/remove-dyn-error
fix: Error type is now Send + Sync
2 parents bfda0c8 + 1e85283 commit 5e332c0

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ressa"
3-
version = "0.9.0-alpha.1"
3+
version = "0.9.0-alpha.2"
44
authors = ["Robert Masen <[email protected]>"]
55
repository = "https://github.com/rusty-ecma/RESSA"
66
description = "An ECMAscript parser"

src/error.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use ress::{tokens::Keyword, Position};
22
use std::fmt::{Display, Formatter, Result};
3+
34
#[derive(Debug)]
45
pub enum Error {
56
UnexpectedEoF,
@@ -43,7 +44,8 @@ pub enum Error {
4344
UndefinedExports(Vec<String>),
4445
ContinueOfNotIterationLabel(Position, String),
4546
Scanner(ress::error::Error),
46-
Other(Box<dyn ::std::error::Error>),
47+
Regex(res_regex::Error),
48+
Io(std::io::Error),
4749
Misc(String),
4850
}
4951

@@ -91,7 +93,8 @@ impl Display for Error {
9193
Error::UndefinedExports(ref names) => write!(f, "Undefined exports in module: {}", names.join(", ")),
9294
Error::ContinueOfNotIterationLabel(ref pos, ref token) => write!(f, "Label `{}` is does not label a loop, continue is invalid at {}", token, pos),
9395
Error::Scanner(ref e) => write!(f, "Error when tokenizing {}", e),
94-
Error::Other(ref e) => write!(f, "{}", e),
96+
Error::Regex(ref e) => write!(f, "{}", e),
97+
Error::Io(ref e) => write!(f, "{}", e),
9598
Error::Misc(ref e) => write!(f, "{}", e),
9699
}
97100
}
@@ -153,7 +156,7 @@ impl Error {
153156

154157
impl From<::std::io::Error> for Error {
155158
fn from(other: ::std::io::Error) -> Self {
156-
Error::Other(Box::new(other))
159+
Error::Io(other)
157160
}
158161
}
159162
impl ::std::error::Error for Error {}
@@ -163,3 +166,25 @@ impl From<ress::error::Error> for Error {
163166
Error::Scanner(other)
164167
}
165168
}
169+
170+
impl From<res_regex::Error> for Error {
171+
fn from(value: res_regex::Error) -> Self {
172+
Self::Regex(value)
173+
}
174+
}
175+
176+
#[cfg(test)]
177+
mod tests {
178+
use super::*;
179+
180+
#[test]
181+
fn error_is_send_and_sync() {
182+
fn print_error<E>(arg: E)
183+
where
184+
E: std::error::Error + Send + Sync,
185+
{
186+
println!("{arg}");
187+
}
188+
print_error(Error::Misc("some misc error".to_string()))
189+
}
190+
}

src/regex.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
use super::{Error, Res};
1+
use super::Res;
22
use res_regex::RegexParser;
33
/// Validate that an already parsed regular expression
44
/// literal does not contain any illegal constructs
55
/// like a duplicate flag or invalid class range
66
pub fn validate_regex<'a>(regex: &'a str) -> Res<()> {
7-
RegexParser::new(&regex)
8-
.map_err(|e| Error::Other(Box::new(e)))?
9-
.validate()
10-
.map_err(|e| Error::Other(Box::new(e)))?;
7+
RegexParser::new(&regex)?.validate()?;
118
Ok(())
129
}

0 commit comments

Comments
 (0)