use get_size2::GetSize; type ExternalVecAlike = Vec; #[derive(GetSize)] struct TestStruct { id: u64, #[get_size(size_fn = vec_alike_helper)] buffer: ExternalVecAlike, } // NOTE: We assume that slice.len()==slice.capacity() fn vec_alike_helper(slice: &V) -> usize where V: AsRef<[T]>, { std::mem::size_of_val(slice.as_ref()) } fn main() { let buffer = vec![0u8; 512]; let buffer: ExternalVecAlike = buffer; let test = TestStruct { id: 1, buffer }; assert_eq!(test.get_heap_size(), 512); }