summaryrefslogtreecommitdiff
path: root/matrix-lang/src/value/exception.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-02-29 21:05:10 -0500
committerFreya Murphy <freya@freyacat.org>2024-02-29 21:05:10 -0500
commitace046624d2e23fba67564a86af7f03ed8a48eae (patch)
tree21ae64bc5897b1b89ee2ab8563b0e7ce047bf34a /matrix-lang/src/value/exception.rs
parentfix readme (diff)
downloadmatrix-ace046624d2e23fba67564a86af7f03ed8a48eae.tar.gz
matrix-ace046624d2e23fba67564a86af7f03ed8a48eae.tar.bz2
matrix-ace046624d2e23fba67564a86af7f03ed8a48eae.zip
remove unwraps, fix utf8
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())
+ })
+ }
+}