get-size-derive2
Derives the GetSize trait of get-size2 for structs and enums.
Usage
This crate is re-exported by get-size2, so depend on that with the derive feature instead of adding it directly:
[]
= { = "^0.10", = ["derive"] }
use GetSize;
assert_eq!;
The generated implementation sums up the heap size of every field, so every field type has to implement GetSize as well. Shared ownership is deduplicated, since the generated implementation threads a tracker through all fields. Unions are not supported.
Attributes
For fields whose type does not implement GetSize, the #[get_size(...)] attribute offers three ways out, plus a struct or enum level escape hatch for generics:
| Attribute | Position | Effect |
|---|---|---|
#[get_size(ignore)] |
Field | Skips the field, contributing 0 |
#[get_size(size = 1024)] |
Field | Accounts the field with a fixed number of bytes |
#[get_size(size_fn = my_helper)] |
Field | Calls my_helper(&field) to determine the heap size |
#[get_size(ignore(A, B))] |
Struct or enum | Drops the GetSize bound on the listed generic types |
Documentation
See docs.rs for the full attribute reference with examples, and docs.rs/get-size2 for the trait itself.
License
This library is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this library by you shall be licensed as MIT, without any additional terms or conditions.