Skip to content

Commit 11e9b81

Browse files
committed
Implement on_err!
1 parent 59180b9 commit 11e9b81

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22
name = "err-rs"
33
version = "0.1.0"
44
edition = "2021"
5-
6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7-
8-
[dependencies]

src/lib.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Copyright 2024 LangVM Project
2-
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0
3-
// that can be found in the LICENSE file and https://mozilla.org/MPL/2.0/.
1+
// Copyright 2024 Jelly Terra
2+
// Use of this source code form is governed under the MIT license.
43

54
#[macro_export]
65
macro_rules! err {
@@ -23,8 +22,18 @@ macro_rules! ok {
2322
macro_rules! wrap_result {
2423
($tag:expr, $expr:expr) => {
2524
match $expr {
26-
Ok(v) => { v }
27-
Err(e) => { return Err($tag(e)); }
25+
Ok(v) => v,
26+
Err(e) => err!($tag, e)
27+
}
28+
};
29+
}
30+
31+
#[macro_export]
32+
macro_rules! on_err {
33+
($expr:expr, $err_name:ident => $err_handle:expr) => {
34+
match $expr {
35+
Ok(v) => v,
36+
Err($err_name) => $err_handle
2837
}
2938
};
3039
}

0 commit comments

Comments
 (0)