1 use heapsize::HeapSize;
2
3 #[derive(HeapSize)]
4 struct Demo<'a, T: ?Sized> {
5 a: Box<T>,
6 b: u8,
7 c: &'a str,
8 d: String,
9 }
10
main()11 fn main() {
12 let demo = Demo {
13 a: b"bytestring".to_vec().into_boxed_slice(),
14 b: 255,
15 c: "&'static str",
16 d: "String".to_owned(),
17 };
18
19 // 10 + 0 + 0 + 6 = 16
20 println!(
21 "heap size = {} + {} + {} + {} = {}",
22 demo.a.heap_size_of_children(),
23 demo.b.heap_size_of_children(),
24 demo.c.heap_size_of_children(),
25 demo.d.heap_size_of_children(),
26 demo.heap_size_of_children()
27 );
28 }
29