diff options
Diffstat (limited to 'matrix-lang/src/value')
-rw-r--r-- | matrix-lang/src/value/exception.rs | 23 | ||||
-rw-r--r-- | matrix-lang/src/value/matrix.rs | 2 |
2 files changed, 23 insertions, 2 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()) + }) + } +} diff --git a/matrix-lang/src/value/matrix.rs b/matrix-lang/src/value/matrix.rs index 91e3ec2..1d55210 100644 --- a/matrix-lang/src/value/matrix.rs +++ b/matrix-lang/src/value/matrix.rs @@ -184,7 +184,7 @@ impl Matrix { let values = rows .into_iter() .reduce(|mut a,b| {a.extend(b); a}) - .unwrap(); + .ok_or(error!("matrix row smashed"))?; Ok(Matrix::new(self.domain + other.domain, self.codomain, values)) } |