#heap #allocation #measurement


Traits for measuring dynamic memory usage of types

3 unstable releases

0.2.1 Sep 24, 2022
0.2.0 Sep 14, 2021
0.1.0 Sep 5, 2021
0.0.0 Sep 3, 2021

#71 in Profiling

Download history 5675/week @ 2023-06-06 6016/week @ 2023-06-13 5105/week @ 2023-06-20 5142/week @ 2023-06-27 5724/week @ 2023-07-04 4199/week @ 2023-07-11 3974/week @ 2023-07-18 2770/week @ 2023-07-25 2020/week @ 2023-08-01 3750/week @ 2023-08-08 4442/week @ 2023-08-15 4041/week @ 2023-08-22 5316/week @ 2023-08-29 5312/week @ 2023-09-05 5726/week @ 2023-09-12 4301/week @ 2023-09-19

21,449 downloads per month
Used in 19 crates (6 directly)


449 lines


This crate contains traits for measuring the dynamic memory usage of Rust types.


Memory-tracking is a common activity in large applications, particularly ones that receive data from a network and store it in memory. By monitoring how much memory is used by different areas of the application, memory pressure can be alleviated by ignoring new packets, or implementing random drop logic for DoS mitigation.

Measuring memory use on the stack is easy, with std::mem::size_of and friends. Measuring memory allocated on the heap is more tricky. Applications can use a custom global allocator to track the memory usage of different areas. This isn't an option for reusable library code however, and the nearest alternative (using custom allocators for individual types) is currently only an experimental feature in nightly Rust (allocator_api).

This crate takes a different approach: it provides traits that library authors can use to expose dynamic memory usage information on their types. By composing these implementations, we gain the ability to query the amount of heap-allocated memory in use by specific instances of types at any point in time, without any changes to the way in which these types are constructed.

Minimum Supported Rust Version

Rust 1.51 or newer.

In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope for this crate's SemVer guarantees), however when we do it will be accompanied by a minor version bump.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.