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

Commit a3c6a79

Browse files
vitiralYamakaky
authored andcommitted
add documentation to quickstart about display (#116)
1 parent 24ffe40 commit a3c6a79

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

examples/quickstart.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ fn main() {
4141
}
4242
}
4343

44+
// The above main gives you maximum control over how the error is
45+
// formatted. If you don't care (i.e. you want to display the full
46+
// error during an assert) you can just call the `display` method
47+
// on the error object
48+
#[allow(dead_code)]
49+
fn alternative_main() {
50+
if let Err(ref e) = run() {
51+
use std::io::Write;
52+
use error_chain::ChainedError; // trait which holds `display`
53+
let stderr = &mut ::std::io::stderr();
54+
let errmsg = "Error writing to stderr";
55+
56+
writeln!(stderr, "{}", e.display()).expect(errmsg);
57+
::std::process::exit(1);
58+
}
59+
}
60+
4461
// Use this macro to auto-generate the main above. You may want to
4562
// set the `RUST_BACKTRACE` env variable to see a backtrace.
4663
//quick_main!(run);
@@ -58,4 +75,3 @@ fn run() -> Result<()> {
5875

5976
Ok(())
6077
}
61-

0 commit comments

Comments
 (0)