Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit bc08c38

Browse files
committed
Result wrapper is optional.
Fixes #49.
1 parent 3c16a22 commit bc08c38

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Error is now a struct.
1111
- The declarations order is more flexible.
1212
- Way better error reporting when there is a syntax error in the macro call.
13+
- `Result` generation can be disabled.
1314

1415
# 0.5.0
1516

src/error_chain.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ macro_rules! error_chain_processed {
1717
types {
1818
$error_name:ident, $error_kind_name:ident, $result_name:ident;
1919
}
20+
$( $rest: tt )*
21+
) => {
22+
error_chain_processed! {
23+
types {
24+
$error_name, $error_kind_name;
25+
}
26+
$( $rest )*
27+
}
28+
/// Convenient wrapper around `std::Result`.
29+
pub type $result_name<T> = ::std::result::Result<T, $error_name>;
30+
};
31+
(
32+
types {
33+
$error_name:ident, $error_kind_name:ident;
34+
}
2035

2136
links {
2237
$( $link_error_path:path, $link_variant:ident $(, #[$meta_links:meta])*; ) *
@@ -204,9 +219,6 @@ macro_rules! error_chain_processed {
204219
e.kind
205220
}
206221
}
207-
208-
/// Convenient wrapper around `std::Result`.
209-
pub type $result_name<T> = ::std::result::Result<T, $error_name>;
210222
};
211223
}
212224

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@
127127
//! Error, ErrorKind, Result;
128128
//! }
129129
//!
130+
//! // Without the `Result` wrapper:
131+
//! //
132+
//! // types {
133+
//! // Error, ErrorKind;
134+
//! // }
135+
//!
130136
//! // Automatic conversions between this error chain and other
131137
//! // error chains. In this case, it will e.g. generate an
132138
//! // `ErrorKind` variant called `Dist` which in turn contains

tests/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,23 @@ mod attributes_test {
389389
}
390390
}
391391
}
392+
393+
#[test]
394+
fn with_result() {
395+
error_chain! {
396+
types {
397+
Error, ErrorKind, Result;
398+
}
399+
}
400+
let _: Result<()> = Ok(());
401+
}
402+
403+
#[test]
404+
fn without_result() {
405+
error_chain! {
406+
types {
407+
Error, ErrorKind;
408+
}
409+
}
410+
let _: Result<(), ()> = Ok(());
411+
}

0 commit comments

Comments
 (0)