summaryrefslogtreecommitdiff
path: root/matrix-lang/src/value/exception.rs
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-lang/src/value/exception.rs')
-rw-r--r--matrix-lang/src/value/exception.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/matrix-lang/src/value/exception.rs b/matrix-lang/src/value/exception.rs
index 0df6f5c..c4ae606 100644
--- a/matrix-lang/src/value/exception.rs
+++ b/matrix-lang/src/value/exception.rs
@@ -1,4 +1,4 @@
-use std::{fmt::{Debug, Display}, error::Error};
+use std::{fmt::{Debug, Display}, error::Error, io};
use crate::prelude::*;
#[macro_export]
@@ -76,3 +76,24 @@ impl<T> From<Exception> for Result<T> {
Err(value)
}
}
+
+impl From<io::Error> for Exception {
+ fn from(value: io::Error) -> Self {
+ exception!(IO_EXCEPTION, "{value}")
+ }
+}
+
+pub trait Except {
+ type Output;
+ fn exception(self) -> Result<Self::Output>;
+}
+
+impl<T, E: std::error::Error> Except for std::result::Result<T, E> {
+ type Output = T;
+
+ fn exception(self) -> Result<Self::Output> {
+ self.map_err(|e| {
+ Exception::msg("unknown", format!("{e}").as_str())
+ })
+ }
+}