Skip to content

Commit

Permalink
add error macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Dec 1, 2023
1 parent 001f0f9 commit 8684cda
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ext/colordom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ fn colordom_error() -> ExceptionClass {
})
}

macro_rules! error {
($ex:ident) => {
Error::new(colordom_error(), $ex.to_string())
};
}

#[derive(Clone)]
#[magnus::wrap(class = "Colordom::Color", free_immediately, size)]
struct Color {
Expand Down Expand Up @@ -58,7 +64,7 @@ impl Image {
fn new(path: PathBuf) -> Result<Self, Error> {
match image::open(&path) {
Ok(img) => Ok(Self { img }),
Err(ex) => Err(Error::new(colordom_error(), ex.to_string()))
Err(ex) => Err(error!(ex))
}
}

Expand Down

0 comments on commit 8684cda

Please sign in to comment.