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

Commit 2d34f22

Browse files
committed
Add util to get the size of Error and such.
1 parent 0bf2ff6 commit 2d34f22

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/size.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
let state = error_chain::State {
25+
next_error: None,
26+
backtrace: None,
27+
};
28+
println!(" State.next_error: {}", size_of_val(&state.next_error));
29+
println!(" State.backtrace: {}", size_of_val(&state.backtrace));
30+
}

0 commit comments

Comments
 (0)