pub trait DeepSizeOf {
// Required method
fn deep_size_of_children(&self, context: &mut Context) -> usize;
// Provided method
fn deep_size_of(&self) -> usize { ... }
}
Expand description
A trait for measuring the size of an object and its children
In many cases this is just std::mem::size_of::<T>()
, but if
the struct contains a Vec
, String
, Box
, or other allocated object or
reference, then it is the size of the struct, plus the size of the contents
of the object.
Required Methods§
Sourcefn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
Returns an estimation of the heap-managed storage of this object. This does not include the size of the object itself.
This is an estimation and not a precise result, because it doesn’t account for allocator’s overhead.
This is an internal function (this shouldn’t be called directly),
and requires a Context
to track visited references.
Implementations of this function should only call deep_size_of_children
,
and not deep_size_of
so that they reference tracking is not reset.
In all other cases, deep_size_of
should be called instead of this function.
If a struct and all of its children do not allocate or have references,
this method should return 0
, as it cannot have any heap allocated
children. There is a shortcut macro for this implementation, known_size_of
,
used like known_deep_size!(0, (), u32, u64);
which generates the impls.
The most common way to use this method, and how the derive works,
is to call this method on each of the structs members and sum the
results, which works as long as all members of the struct implement
DeepSizeOf
.
To implement this for a collection type, you should sum the deep sizes of the items of the collection and then add the size of the allocation of the collection itself. This can become much more complicated if the collection has multiple separate allocations.
Here is an example from the implementation of DeepSizeOf
for Vec<T>
impl<T> DeepSizeOf for std::vec::Vec<T> where T: DeepSizeOf {
fn deep_size_of_children(&self, context: &mut Context) -> usize {
// Size of heap allocations for each child
self.iter().map(|child| child.deep_size_of_children(context)).sum()
+ self.capacity() * std::mem::size_of::<T>() // Size of Vec's heap allocation
}
}
Provided Methods§
Sourcefn deep_size_of(&self) -> usize
fn deep_size_of(&self) -> usize
Returns an estimation of a total size of memory owned by the object, including heap-managed storage.
This is an estimation and not a precise result because it doesn’t account for allocator’s overhead.
use deepsize::DeepSizeOf;
let mut map: Vec<(Box<u32>, String)> = Vec::new();
map.push((Box::new(42u32), String::from("Hello World")));
map.push((Box::new(20u32), String::from("Something")));
map.push((Box::new(0u32), String::from("A string")));
map.push((Box::new(255u32), String::from("Dynamically Allocated!")));
assert_eq!(map.deep_size_of(),
std::mem::size_of::<Vec<(Box<u32>, String)>>() +
4 * std::mem::size_of::<(Box<u32>, String)>() +
4 * std::mem::size_of::<u32>() +
11 + 9 + 8 + 22
);
Implementations on Foreign Types§
Source§impl DeepSizeOf for bool
impl DeepSizeOf for bool
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for char
impl DeepSizeOf for char
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for f32
impl DeepSizeOf for f32
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for f64
impl DeepSizeOf for f64
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for i8
impl DeepSizeOf for i8
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for i16
impl DeepSizeOf for i16
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for i32
impl DeepSizeOf for i32
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for i64
impl DeepSizeOf for i64
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for i128
impl DeepSizeOf for i128
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for isize
impl DeepSizeOf for isize
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for str
impl DeepSizeOf for str
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for u8
impl DeepSizeOf for u8
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for u16
impl DeepSizeOf for u16
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for u32
impl DeepSizeOf for u32
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for u64
impl DeepSizeOf for u64
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for u128
impl DeepSizeOf for u128
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for ()
impl DeepSizeOf for ()
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for usize
impl DeepSizeOf for usize
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for CString
impl DeepSizeOf for CString
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for String
impl DeepSizeOf for String
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for CStr
impl DeepSizeOf for CStr
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<i8>
impl DeepSizeOf for NonZero<i8>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<i16>
impl DeepSizeOf for NonZero<i16>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<i32>
impl DeepSizeOf for NonZero<i32>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<i64>
impl DeepSizeOf for NonZero<i64>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<i128>
impl DeepSizeOf for NonZero<i128>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<isize>
impl DeepSizeOf for NonZero<isize>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<u8>
impl DeepSizeOf for NonZero<u8>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<u16>
impl DeepSizeOf for NonZero<u16>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<u32>
impl DeepSizeOf for NonZero<u32>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<u64>
impl DeepSizeOf for NonZero<u64>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<u128>
impl DeepSizeOf for NonZero<u128>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for NonZero<usize>
impl DeepSizeOf for NonZero<usize>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicBool
impl DeepSizeOf for AtomicBool
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicI8
impl DeepSizeOf for AtomicI8
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicI16
impl DeepSizeOf for AtomicI16
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicI32
impl DeepSizeOf for AtomicI32
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicI64
impl DeepSizeOf for AtomicI64
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicIsize
impl DeepSizeOf for AtomicIsize
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicU8
impl DeepSizeOf for AtomicU8
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicU16
impl DeepSizeOf for AtomicU16
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicU32
impl DeepSizeOf for AtomicU32
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicU64
impl DeepSizeOf for AtomicU64
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for AtomicUsize
impl DeepSizeOf for AtomicUsize
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for OsStr
impl DeepSizeOf for OsStr
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for OsString
impl DeepSizeOf for OsString
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for Path
impl DeepSizeOf for Path
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl DeepSizeOf for PathBuf
impl DeepSizeOf for PathBuf
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl<A> DeepSizeOf for (A,)where
A: DeepSizeOf,
impl<A> DeepSizeOf for (A,)where
A: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B> DeepSizeOf for (A, B)where
A: DeepSizeOf,
B: DeepSizeOf,
impl<A, B> DeepSizeOf for (A, B)where
A: DeepSizeOf,
B: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C> DeepSizeOf for (A, B, C)
impl<A, B, C> DeepSizeOf for (A, B, C)
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C, D> DeepSizeOf for (A, B, C, D)
impl<A, B, C, D> DeepSizeOf for (A, B, C, D)
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C, D, E> DeepSizeOf for (A, B, C, D, E)
impl<A, B, C, D, E> DeepSizeOf for (A, B, C, D, E)
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C, D, E, F> DeepSizeOf for (A, B, C, D, E, F)
impl<A, B, C, D, E, F> DeepSizeOf for (A, B, C, D, E, F)
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C, D, E, F, G> DeepSizeOf for (A, B, C, D, E, F, G)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
impl<A, B, C, D, E, F, G> DeepSizeOf for (A, B, C, D, E, F, G)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C, D, E, F, G, H> DeepSizeOf for (A, B, C, D, E, F, G, H)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
H: DeepSizeOf,
impl<A, B, C, D, E, F, G, H> DeepSizeOf for (A, B, C, D, E, F, G, H)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
H: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C, D, E, F, G, H, I> DeepSizeOf for (A, B, C, D, E, F, G, H, I)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
H: DeepSizeOf,
I: DeepSizeOf,
impl<A, B, C, D, E, F, G, H, I> DeepSizeOf for (A, B, C, D, E, F, G, H, I)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
H: DeepSizeOf,
I: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<A, B, C, D, E, F, G, H, I, J> DeepSizeOf for (A, B, C, D, E, F, G, H, I, J)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
H: DeepSizeOf,
I: DeepSizeOf,
J: DeepSizeOf,
impl<A, B, C, D, E, F, G, H, I, J> DeepSizeOf for (A, B, C, D, E, F, G, H, I, J)where
A: DeepSizeOf,
B: DeepSizeOf,
C: DeepSizeOf,
D: DeepSizeOf,
E: DeepSizeOf,
F: DeepSizeOf,
G: DeepSizeOf,
H: DeepSizeOf,
I: DeepSizeOf,
J: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<K> DeepSizeOf for BTreeSet<K>where
K: Ord + DeepSizeOf,
impl<K> DeepSizeOf for BTreeSet<K>where
K: Ord + DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<K, S> DeepSizeOf for HashSet<K, S>
impl<K, S> DeepSizeOf for HashSet<K, S>
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<K, V> DeepSizeOf for BTreeMap<K, V>
impl<K, V> DeepSizeOf for BTreeMap<K, V>
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<K, V, S> DeepSizeOf for HashMap<K, V, S>
impl<K, V, S> DeepSizeOf for HashMap<K, V, S>
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<R, E> DeepSizeOf for Result<R, E>where
R: DeepSizeOf,
E: DeepSizeOf,
impl<R, E> DeepSizeOf for Result<R, E>where
R: DeepSizeOf,
E: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for Option<T>where
T: DeepSizeOf,
impl<T> DeepSizeOf for Option<T>where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 0]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 0]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 1]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 1]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 2]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 2]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 3]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 3]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 4]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 4]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 5]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 5]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 6]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 6]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 7]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 7]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 8]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 8]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 9]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 9]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 10]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 10]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 11]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 11]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 12]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 12]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 13]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 13]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 14]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 14]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 15]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 15]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 16]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 16]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 17]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 17]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 18]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 18]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 19]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 19]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 20]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 20]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 21]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 21]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 22]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 22]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 23]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 23]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 24]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 24]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 25]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 25]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 26]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 26]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 27]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 27]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 28]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 28]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 29]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 29]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 30]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 30]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 31]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 31]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T; 32]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T; 32]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for &Twhere
T: DeepSizeOf + ?Sized,
impl<T> DeepSizeOf for &Twhere
T: DeepSizeOf + ?Sized,
fn deep_size_of_children(&self, _context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for &mut Twhere
T: DeepSizeOf + ?Sized,
impl<T> DeepSizeOf for &mut Twhere
T: DeepSizeOf + ?Sized,
fn deep_size_of_children(&self, _context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for [T]where
T: DeepSizeOf,
impl<T> DeepSizeOf for [T]where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for Box<T>where
T: DeepSizeOf + ?Sized,
impl<T> DeepSizeOf for Box<T>where
T: DeepSizeOf + ?Sized,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for LinkedList<T>where
T: DeepSizeOf,
impl<T> DeepSizeOf for LinkedList<T>where
T: DeepSizeOf,
Source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
Sums the size of each child object, assuming the overhead of each node is 2 usize (next, prev)
use deepsize::DeepSizeOf;
use std::collections::LinkedList;
let mut list: LinkedList<u8> = LinkedList::new();
for i in 0..12 {
list.push_back(i);
}
list.push_front(13);
assert_eq!(list.deep_size_of(), std::mem::size_of::<LinkedList<u8>>()
+ 13 * 1 + 13 * 2 * 8);
Source§impl<T> DeepSizeOf for VecDeque<T>where
T: DeepSizeOf,
impl<T> DeepSizeOf for VecDeque<T>where
T: DeepSizeOf,
Source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
Sums the size of each child object, and then adds the size of the unused capacity.
use deepsize::DeepSizeOf;
use std::collections::VecDeque;
let mut vec: VecDeque<u8> = VecDeque::new();
for i in 0..12 {
vec.push_back(i);
}
vec.push_front(13);
// The capacity (15?) plus four usizes (start, end, cap, pointer)
assert_eq!(vec.deep_size_of(), vec.capacity() * 1 + 32);
With allocated objects:
use deepsize::DeepSizeOf;
use std::collections::VecDeque;
let mut vec: VecDeque<Box<u64>> = VecDeque::new();
for i in 0..12 {
vec.push_back(Box::new(i));
}
vec.push_front(Box::new(13));
// The capacity (15?) * size (8) plus four usizes (start, end, cap, pointer)
// and length (13) * the allocated size of each object
assert_eq!(vec.deep_size_of(), 32 + vec.capacity() * 8 + 13 * 8);
Source§impl<T> DeepSizeOf for Rc<T>where
T: DeepSizeOf + ?Sized,
impl<T> DeepSizeOf for Rc<T>where
T: DeepSizeOf + ?Sized,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for Weak<T>
impl<T> DeepSizeOf for Weak<T>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl<T> DeepSizeOf for Arc<T>where
T: DeepSizeOf + ?Sized,
impl<T> DeepSizeOf for Arc<T>where
T: DeepSizeOf + ?Sized,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for Weak<T>
impl<T> DeepSizeOf for Weak<T>
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl<T> DeepSizeOf for Vec<T>where
T: DeepSizeOf,
impl<T> DeepSizeOf for Vec<T>where
T: DeepSizeOf,
Source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
Sums the size of each child object, and then adds the size of the unused capacity.
use deepsize::DeepSizeOf;
let mut vec: Vec<u8> = vec![];
for i in 0..13 {
vec.push(i);
}
// The capacity (16) plus three usizes (len, cap, pointer)
assert_eq!(vec.deep_size_of(), 16 + 24);
With allocated objects:
use deepsize::DeepSizeOf;
let mut vec: Vec<Box<u64>> = vec![];
for i in 0..13 {
vec.push(Box::new(i));
}
// The capacity (16?) * size (8) plus three usizes (len, cap, pointer)
// and length (13) * the allocated size of each object
assert_eq!(vec.deep_size_of(), 24 + vec.capacity() * 8 + 13 * 8);
Source§impl<T> DeepSizeOf for Cell<T>where
T: Copy,
impl<T> DeepSizeOf for Cell<T>where
T: Copy,
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl<T> DeepSizeOf for RefCell<T>where
T: DeepSizeOf,
impl<T> DeepSizeOf for RefCell<T>where
T: DeepSizeOf,
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§impl<T> DeepSizeOf for PhantomData<T>where
T: ?Sized,
impl<T> DeepSizeOf for PhantomData<T>where
T: ?Sized,
fn deep_size_of_children(&self, _: &mut Context) -> usize
Source§impl<T> DeepSizeOf for Mutex<T>where
T: DeepSizeOf,
impl<T> DeepSizeOf for Mutex<T>where
T: DeepSizeOf,
Source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
This locks the Mutex
, so it may deadlock; If the mutex is
poisoned, this returns 0
Source§impl<T> DeepSizeOf for RwLock<T>where
T: DeepSizeOf,
impl<T> DeepSizeOf for RwLock<T>where
T: DeepSizeOf,
Source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
This reads the RwLock
, so it may deadlock; If the lock is
poisoned, this returns 0