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

Commit bce3d99

Browse files
committed
Variant(Error) in links and foreign_links.
It uniforms the syntax with `errors`.
1 parent a44610c commit bce3d99

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
3+
- New `Variant(Error) #[attrs]` for `links` and `foreign_links`.
4+
15
# 0.6.0
26

37
- Conditional compilation for error variants.

examples/all.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ error_chain! {
2222

2323
// Automatic bindings to others error types generated by `error_chain!`.
2424
links {
25-
inner::Error, Inner;
25+
Inner(inner::Error);
2626
// Attributes can be added at the end of the declaration.
27-
feature::Error, Feature, #[cfg(feature = "a_feature")];
27+
Feature(feature::Error) #[cfg(feature = "a_feature")];
2828
}
2929

3030
// Bindings to types implementing std::error::Error.
3131
foreign_links {
32-
::std::io::Error, Io;
32+
Io(::std::io::Error);
3333
}
3434
}
3535

examples/doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ pub mod inner {
1313

1414
error_chain! {
1515
links {
16-
inner::Error, Test, #[doc = "Doc"];
16+
Inner(inner::Error) #[doc = "Doc"];
1717
}
1818
foreign_links {
19-
::std::io::Error, Io, #[doc = "Io"];
19+
Io(::std::io::Error) #[doc = "Io"];
2020
}
2121
errors {
2222
/// Doc

src/error_chain.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ macro_rules! error_chain_processed {
1313
$( $rest )*
1414
}
1515
};
16+
// With `Result` wrapper.
1617
(
1718
types {
1819
$error_name:ident, $error_kind_name:ident, $result_name:ident;
@@ -28,17 +29,20 @@ macro_rules! error_chain_processed {
2829
/// Convenient wrapper around `std::Result`.
2930
pub type $result_name<T> = ::std::result::Result<T, $error_name>;
3031
};
32+
// Without `Result` wrapper.
3133
(
3234
types {
3335
$error_name:ident, $error_kind_name:ident;
3436
}
3537

3638
links {
37-
$( $link_error_path:path, $link_variant:ident $(, #[$meta_links:meta])*; ) *
39+
$( $link_variant:ident ( $link_error_path:path )
40+
$( #[$meta_links:meta] )*; ) *
3841
}
3942

4043
foreign_links {
41-
$( $foreign_link_error_path:path, $foreign_link_variant:ident $(, #[$meta_foreign_links:meta])*; )*
44+
$( $foreign_link_variant:ident ( $foreign_link_error_path:path )
45+
$( #[$meta_foreign_links:meta] )*; )*
4246
}
4347

4448
errors {

src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@
117117
//! Assuming you are using crate-level error types, typically you will
118118
//! define an `errors` module and inside it call `error_chain!`:
119119
//!
120-
//! ```ignore
120+
//! ```
121+
//! # #[macro_use] extern crate error_chain;
122+
//! mod other_error {
123+
//! error_chain! {}
124+
//! }
125+
//!
121126
//! error_chain! {
122127
//! // The type defined for this error. These are the conventional
123128
//! // and recommended names, but they can be arbitrarily chosen.
@@ -143,8 +148,7 @@
143148
//! //
144149
//! // This section can be empty.
145150
//! links {
146-
//! ::rustup_dist::Error, Dist;
147-
//! ::rustup_utils::Error, Utils, #[cfg(unix)];
151+
//! Another(other_error::Error) #[cfg(unix)];
148152
//! }
149153
//!
150154
//! // Automatic conversions between this error chain and other
@@ -157,8 +161,8 @@
157161
//! //
158162
//! // This section can be empty.
159163
//! foreign_links {
160-
//! ::temp::Error, Temp;
161-
//! io::Error, Io, #[cfg(unix)];
164+
//! Fmt(::std::fmt::Error);
165+
//! Io(::std::io::Error) #[cfg(unix)];
162166
//! }
163167
//!
164168
//! // Define additional `ErrorKind` variants. The syntax here is
@@ -171,6 +175,8 @@
171175
//! }
172176
//! }
173177
//! }
178+
//!
179+
//! # fn main() {}
174180
//! ```
175181
//!
176182
//! Each section, `types`, `links`, `foreign_links`, and `errors` may

tests/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn chain_err() {
241241

242242
error_chain! {
243243
foreign_links {
244-
fmt::Error, Fmt;
244+
Fmt(fmt::Error);
245245
}
246246
errors {
247247
Test
@@ -260,7 +260,7 @@ fn links() {
260260

261261
error_chain! {
262262
links {
263-
test::Error, Test;
263+
Test(test::Error);
264264
}
265265
}
266266
}
@@ -314,8 +314,8 @@ mod foreign_link_test {
314314
}
315315
links {}
316316
foreign_links {
317-
ForeignError, Foreign;
318-
::std::io::Error, Io;
317+
Foreign(ForeignError);
318+
Io(::std::io::Error);
319319
}
320320
errors {}
321321
}
@@ -382,11 +382,11 @@ mod attributes_test {
382382
}
383383

384384
links {
385-
inner::Error, Inner, #[cfg(not(test))];
385+
Inner(inner::Error) #[cfg(not(test))];
386386
}
387387

388388
foreign_links {
389-
io::Error, Io, #[cfg(not(test))];
389+
Io(io::Error) #[cfg(not(test))];
390390
}
391391

392392
errors {
@@ -426,10 +426,10 @@ fn documentation() {
426426

427427
error_chain! {
428428
links {
429-
inner::Error, Inner, #[doc = "Doc"];
429+
Inner(inner::Error) #[doc = "Doc"];
430430
}
431431
foreign_links {
432-
::std::io::Error, Io, #[doc = "Doc"];
432+
Io(::std::io::Error) #[doc = "Doc"];
433433
}
434434
errors {
435435
/// Doc

0 commit comments

Comments
 (0)