Determine the size in bytes an object occupies inside RAM.
size_of already reports how many bytes a value occupies on the stack. Applications like caches or memory budgets also need to know how many bytes a value owns on the heap, which is what the GetSize trait adds.
This repository is a fork of get-size, which is no longer maintained.
cargo add get-size2 --features deriveuse get_size2::GetSize;
#[derive(GetSize)]
struct Data {
name: String,
id: u64,
}
let data = Data { name: "Hello".into(), id: 1 };
assert_eq!(data.get_heap_size(), 5);
assert_eq!(data.get_size(), Data::get_stack_size() + 5);| Crate | Description | Documentation |
|---|---|---|
get-size2 |
The GetSize trait, its implementations and the trackers |
docs.rs |
get-size-derive2 |
The #[derive(GetSize)] macro, re-exported by get-size2 |
docs.rs |
The crate is no_std compatible and ships optional implementations for 18 third party crates, see the get-size2 README.
Issues and pull requests are welcome. cargo test --all --all-features, cargo clippy --all-targets --all-features -- -D warnings and cargo fmt --all should pass; CI additionally builds a 32-bit and a bare metal no_std target.
The crate itself and the derive feature build with Rust 1.85. The optional integrations follow the requirements of the crates they integrate, which are often newer; cargo reports the version a feature needs.
This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you shall be licensed as MIT, without any additional terms or conditions.