1use crate::MemoryReport;
6use alloc::{
7 collections::VecDeque,
8 vec::Vec,
9};
10
11
12
13impl<T: MemoryReport> MemoryReport for Vec<T> {
14 const ALLOC: bool = true;
15 const CHILD: bool = true;
16
17 fn indirect(&self) -> usize {
18 self.capacity() * T::direct()
19 }
20
21 fn children(&self) -> usize {
22 if !(T::ALLOC || T::CHILD) { return 0; }
23
24 self.iter().map(|x| x.indirect() + x.children()).sum()
25 }
26}
27
28
29
30impl<T: MemoryReport> MemoryReport for VecDeque<T> {
31 const ALLOC: bool = true;
32 const CHILD: bool = true;
33
34 fn indirect(&self) -> usize {
35 self.capacity() * T::direct()
36 }
37
38 fn children(&self) -> usize {
39 if !(T::ALLOC || T::CHILD) { return 0; }
40
41 self.iter().map(|x| x.indirect() + x.children()).sum()
42 }
43}
44
45
46
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn direct() {
54 assert!((core::mem::size_of::<usize>() * 3) == Vec::<u64>::direct());
55 }
56
57 #[test]
58 fn indirect() {
59 assert!((core::mem::size_of::<usize>() * 4) == Vec::<u64>::with_capacity(4).indirect());
60 }
61
62 #[test]
63 fn children() {
64 assert!(0 == alloc::vec![0usize, 1, 2, 3].children());
65 }
66}