-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathmain.rs
More file actions
46 lines (39 loc) · 1.09 KB
/
main.rs
File metadata and controls
46 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::path::Path;
use human_panic::metadata;
use human_panic::Metadata;
use human_panic::setup_panic;
fn custom_message(
buf: &mut dyn std::io::Write,
path: Option<&Path>,
meta: &Metadata
) -> std::io::Result<()> {
let Metadata {
name,
homepage,
..
} = meta;
writeln!(buf, "A fatal error ocurred!")?;
writeln!(buf,"{name} is DEAD :(")?;
writeln!(
buf,
"You can see details at \"{}\".",
match path {
Some(fp) => format!("{}", fp.display()),
None => "<Failed to store file to disk>".to_owned(),
},
)?;
if let Some(homepage) = homepage {
writeln!(buf, "\nShare your condolences: {homepage}")?;
}
Ok(())
}
fn main() {
setup_panic!(
metadata!()
.authors("My Company Support <support@mycompany.com>")
.homepage("www.mycompany.com")
.support("- Open a support request by email to support@mycompany.com"),
custom_message);
println!("A normal log message");
panic!("OMG EVERYTHING IS ON FIRE!!!");
}