I am trying to figure out how to get the size in bytes of an object in Rust where the size may or may not be known at compile time. I would like to be able to fetch the number of bytes at any point during the runtime of the program. Here's an example.
let mut v: Vec<SomeStruct> = Vec::new();
loop {
v.push(get_some_struct());
print_consumed_memory_of_vec(&v);
}
I would like to have a more generic way this than doing mem::size_of<SomeStruct> * v.len()
because often you have a trait or something where the size is not known at compile time.