11use ress:: { tokens:: Keyword , Position } ;
22use std:: fmt:: { Display , Formatter , Result } ;
3+
34#[ derive( Debug ) ]
45pub 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
154157impl 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}
159162impl :: 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+ }
0 commit comments