Crates.io | heapsz |
lib.rs | heapsz |
version | 0.1.0 |
source | src |
created_at | 2024-04-25 14:11:04.512389 |
updated_at | 2024-05-14 09:42:30.415187 |
description | A crate for calculating the heap usage of a data structure. |
homepage | |
repository | https://github.com/overvenus/heapsz |
max_upload_size | |
id | 1220335 |
size | 67,844 |
A crate for calculating the heap usage of a data structure.
It's simple. Only one required method in the HeapSize
trait, which can be
generated by #[derive(HeapSize)]
.
It's fast. It estimates an approximate heap size in O(1) time.
Calculate heap_size()
selectively
Example | Expanded example |
---|---|
|
|
heap_size()
of all fieldsExample | Expanded example |
---|---|
|
|
Example | Expanded example |
---|---|
|
|
Example | Expanded example |
---|---|
|
|
#[derive(HeapSize)]
Apply to one field in a struct or in an enum variant.
#[heap_size]
By default, #[derive(HeapSize)]
generates an empty implementation which
always return 0. #[heap_size]
needs to be added to fields that have a heap
allocation.
This is because of 1) most struct does not contain heap allocation at all,
and 2) they often do not implement the HeapSize
trait.
#[heap_size(skip)]
Skip this field: do not calculate its heap size.
Requires a struct has a container attribute #[heap_size]
.
#[heap_size(with = "module")]
#[derive(HeapSize)]
will use $module::heap_size
as the function to obtain
this field’s heap size.
Apply to a struct or enum declaration.
#[heap_size]
By default, #[derive(HeapSize)]
generates an empty implementation that
always return 0. By adding #[heap_size]
, it sums up heap_size()
of all
fields in a struct or an enum.Apply to a variant of an enum.
#[heap_size]
Generate
By default, #[derive(HeapSize)]
generates an empty implementation which
always return 0. By adding #[heap_size]
, it sums up heap_size()
of fields
in a variant.
#[heap_size(skip)]
Skip this variant: do not calculate its heap size.
Requires an enum has a #[heap_size]
container attribute.
This project is licensed under the MIT license.