summaryrefslogtreecommitdiffstats
path: root/third_party/rust/error-chain/examples/size.rs
blob: 3e180684e812c40f973e060a6a1f931f8646ab86 (plain)
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
#[macro_use]
extern crate error_chain;

use std::mem::{size_of, size_of_val};

error_chain! {
    errors {
        AVariant
        Another
    }
}

fn main() {
    println!("Memory usage in bytes");
    println!("---------------------");
    println!("Result<()>: {}", size_of::<Result<()>>());
    println!("  (): {}", size_of::<()>());
    println!("  Error: {}", size_of::<Error>());
    println!("    ErrorKind: {}", size_of::<ErrorKind>());
    let msg = ErrorKind::Msg("test".into());
    println!("      ErrorKind::Msg: {}", size_of_val(&msg));
    println!("        String: {}", size_of::<String>());
    println!("    State: {}", size_of::<error_chain::State>());
    let state = error_chain::State {
        next_error: None,
        backtrace: error_chain::InternalBacktrace::new(),
    };
    println!("      State.next_error: {}", size_of_val(&state.next_error));
    println!("      State.backtrace: {}", size_of_val(&state.backtrace));
}