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

Commit dd4551d

Browse files
committed
Move example_generated to own file.
1 parent 605beac commit dd4551d

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ repository = "https://github.com/brson/error-chain"
1515
license = "MIT/Apache-2.0"
1616

1717
[features]
18-
default = ["backtrace"]
18+
default = ["backtrace", "example_generated"]
19+
example_generated = []
1920

2021
[dependencies]
2122
backtrace = { version = "0.3", optional = true }

src/example_generated.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! This modules show an example of code generated by the macro. IT MUST NOT BE
2+
//! USED OUTSIDE THIS CRATE.
3+
//!
4+
//! This is the basic error structure. You can see that `ErrorKind`
5+
//! has been populated in a variety of ways. All `ErrorKind`s get a
6+
//! `Msg` variant for basic errors. When strings are converted to
7+
//! `ErrorKind`s they become `ErrorKind::Msg`. The "links" defined in
8+
//! the macro are expanded to the `Inner` variant, and the
9+
//! "foreign links" to the `Io` variant.
10+
//!
11+
//! Both types come with a variety of `From` conversions as well:
12+
//! `Error` can be created from `ErrorKind`, `&str` and `String`,
13+
//! and the `links` and `foreign_links` error types. `ErrorKind`
14+
//! can be created from the corresponding `ErrorKind`s of the link
15+
//! types, as well as from `&str` and `String`.
16+
//!
17+
//! `into()` and `From::from` are used heavily to massage types into
18+
//! the right shape. Which one to use in any specific case depends on
19+
//! the influence of type inference, but there are some patterns that
20+
//! arise frequently.
21+
22+
/// Another code generated by the macro.
23+
pub mod inner {
24+
error_chain! {}
25+
}
26+
27+
error_chain! {
28+
links {
29+
Inner(inner::Error) #[doc = "Link to another `ErrorChain`."];
30+
}
31+
foreign_links {
32+
Io(::std::io::Error) #[doc = "Link to a `std::error::Error` type."];
33+
}
34+
errors {
35+
#[doc = "A custom error kind."]
36+
Custom
37+
}
38+
}

src/lib.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ pub type Backtrace = ();
269269
mod quick_error;
270270
#[macro_use]
271271
mod error_chain;
272+
#[cfg(feature = "example_generated")]
273+
pub mod example_generated;
272274

273275
/// Iterator over the error chain.
274276
pub struct ErrorChainIter<'a>(pub Option<&'a error::Error>);
@@ -389,43 +391,3 @@ impl State {
389391
b
390392
}
391393
}
392-
393-
/// This modules show an example of code generated by the macro. IT MUST NOT BE
394-
/// USED OUTSIDE THIS CRATE.
395-
///
396-
/// This is the basic error structure. You can see that `ErrorKind`
397-
/// has been populated in a variety of ways. All `ErrorKind`s get a
398-
/// `Msg` variant for basic errors. When strings are converted to
399-
/// `ErrorKind`s they become `ErrorKind::Msg`. The "links" defined in
400-
/// the macro are expanded to the `Inner` variant, and the
401-
/// "foreign links" to the `Io` variant.
402-
///
403-
/// Both types come with a variety of `From` conversions as well:
404-
/// `Error` can be created from `ErrorKind`, `&str` and `String`,
405-
/// and the `links` and `foreign_links` error types. `ErrorKind`
406-
/// can be created from the corresponding `ErrorKind`s of the link
407-
/// types, as well as from `&str` and `String`.
408-
///
409-
/// `into()` and `From::from` are used heavily to massage types into
410-
/// the right shape. Which one to use in any specific case depends on
411-
/// the influence of type inference, but there are some patterns that
412-
/// arise frequently.
413-
pub mod example_generated {
414-
/// Another code generated by the macro.
415-
pub mod inner {
416-
error_chain! {}
417-
}
418-
419-
error_chain! {
420-
links {
421-
Inner(inner::Error) #[doc = "Link to another `ErrorChain`."];
422-
}
423-
foreign_links {
424-
Io(::std::io::Error) #[doc = "Link to a `std::error::Error` type."];
425-
}
426-
errors {
427-
#[doc = "A custom error kind."]
428-
Custom
429-
}
430-
}
431-
}

0 commit comments

Comments
 (0)