#[macro_use] extern crate heapsize_derive; mod heapsize { pub trait HeapSizeOf { fn heap_size_of_children(&self) -> usize; } impl HeapSizeOf for Box { fn heap_size_of_children(&self) -> usize { ::std::mem::size_of::() } } } #[derive(HeapSizeOf)] struct Foo([Box; 2], Box); #[test] fn test() { use heapsize::HeapSizeOf; assert_eq!(Foo([Box::new(1), Box::new(2)], Box::new(3)).heap_size_of_children(), 9); }