Expand description
§Typesize
A library to fetch an accurate estimate of the total memory usage of a value.
The goal of this library is to produce the most accurate estimate possible, however without being deeply
integrated into the entire ecosystem this cannot be possible. This leads to the real goal being to get
“close enough” for getting a sense of memory usage in your program. If one of the TypeSize
implementations built-in could be improved, a PR would be greatly appreciated.
An example usage of this library would be to wrap all the types you want to measure recursively in
the derive::TypeSize derive macro, and for any types which perform their own heap allocation
to manually implement TypeSize while overriding the TypeSize::extra_size method.
§MSRV
The Minimum Supported Rust Version is of this crate is 1.65, and it is considered breaking to raise this.
This is without any library support features, as those libraries may require a higher MSRV.
§Features
std: ImplementsTypeSizeforHashMapandHashSet, default enabled.details: AddsTypeSize::get_size_detailsandTypeSize::get_collection_item_countto get field by field breakdowns of struct types.
§Library Support
dashmap: ImplementsTypeSizeforDashMap(Only5.x, use thetypesizefeature of dashmap for6.1+).arrayvec: ImplementsTypeSizeforArrayVecandArrayStringof any size.simd_json: ImplementsTypeSizeforOwnedValueandStaticNode, enables halfbrown.halfbrown: ImplementsTypeSizeforSizedHashMap, enables hashbrown.extract_map_01: ImplementsTypeSizeforextract_map::ExtractMap.parking_lot: ImplementsTypeSizeforparking_lot::Mutexandparking_lot::RwLock.serde_json: ImplementsTypeSizeforserde_json::Valueandserde_json::Map.mini_moka: ImplementsTypeSizeformini_moka::unsync::Cache, andmini_moka::sync::Cacheifdashmapis enabled.hashbrown: ImplementsTypeSizeforhashbrown_14::HashMap(version 0.14.x).hashbrown_15: ImplementsTypeSizeforhashbrown_15::HashMap(version 0.15.x).secrecy: ImplementsTypeSizeforSecret.chrono: ImplementsTypeSizeforchrono::DateTimeof anychrono::TimeZone.nonmax: ImplementsTypeSizefor allnonmaxtypes.time: ImplementsTypeSizefor [time::OffsetDateTime].url: ImplementsTypeSizeforurl::Url.bitvec: ImplementsTypeSizeforbitvec::array::BitArrayandbitvec::vec::BitVec.web-time: ImplementsTypeSizeforweb_time::Instantandweb_time::SystemTime(on platforms where these aren’t type aliases tostd::timetypes).
Re-exports§
Modules§
Macros§
- if_
typesize_ details - Passes through the given tokens if the
detailsfeature oftypesizeis enabled. - sizeof_
impl - Implements
TypeSizefor multiple types based on the return value ofcore::mem::size_of.
Structs§
- Field
- A description of a struct or enum field.
Traits§
- Type
Size - A trait to fetch an accurate estimate of the total memory usage of a value.