]> git.proxmox.com Git - rustc.git/blob - vendor/error-chain-0.11.0/examples/size.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / vendor / error-chain-0.11.0 / examples / size.rs
1 #[macro_use]
2 extern crate error_chain;
3
4 use std::mem::{size_of, size_of_val};
5
6 error_chain! {
7 errors {
8 AVariant
9 Another
10 }
11 }
12
13 fn main() {
14 println!("Memory usage in bytes");
15 println!("---------------------");
16 println!("Result<()>: {}", size_of::<Result<()>>());
17 println!(" (): {}", size_of::<()>());
18 println!(" Error: {}", size_of::<Error>());
19 println!(" ErrorKind: {}", size_of::<ErrorKind>());
20 let msg = ErrorKind::Msg("test".into());
21 println!(" ErrorKind::Msg: {}", size_of_val(&msg));
22 println!(" String: {}", size_of::<String>());
23 println!(" State: {}", size_of::<error_chain::State>());
24 #[cfg(feature = "backtrace")]
25 {
26 let state = error_chain::State {
27 next_error: None,
28 backtrace: None,
29 };
30 println!(" State.next_error: {}", size_of_val(&state.next_error));
31 println!(" State.backtrace: {}", size_of_val(&state.backtrace));
32 }
33 #[cfg(not(feature = "backtrace"))]
34 {
35 let state = error_chain::State { next_error: None };
36 println!(" State.next_error: {}", size_of_val(&state.next_error));
37 }
38 }