{"id":16766519,"url":"https://github.com/overvenus/heapsz","last_synced_at":"2026-06-06T04:31:08.609Z","repository":{"id":238441958,"uuid":"796560871","full_name":"overvenus/heapsz","owner":"overvenus","description":"A crate for calculating the heap usage of a data structure.","archived":false,"fork":false,"pushed_at":"2024-05-14T09:43:40.000Z","size":77,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T06:20:26.760Z","etag":null,"topics":["derive","memory-management","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/overvenus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-06T07:29:12.000Z","updated_at":"2024-05-15T07:51:45.000Z","dependencies_parsed_at":"2024-05-14T05:31:00.317Z","dependency_job_id":"cfb57716-7ea1-4280-b0f7-013d27849b07","html_url":"https://github.com/overvenus/heapsz","commit_stats":null,"previous_names":["overvenus/heapsz"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overvenus%2Fheapsz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overvenus%2Fheapsz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overvenus%2Fheapsz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overvenus%2Fheapsz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/overvenus","download_url":"https://codeload.github.com/overvenus/heapsz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241680449,"owners_count":20002106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["derive","memory-management","rust"],"created_at":"2024-10-13T06:06:42.781Z","updated_at":"2026-06-06T04:31:08.574Z","avatar_url":"https://github.com/overvenus.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# heapsz\n\nA crate for calculating the heap usage of a data structure.\n\nIt's simple. Only one required method in the `HeapSize` trait, which can be\ngenerated by `#[derive(HeapSize)]`.\n\nIt's fast. It estimates an approximate heap size in O(1) time.\n\n## Usage\n\n### Examples\n\n\u003c!-- Begin **Calculate `heap_size()` selectively** --\u003e\n\n**Calculate `heap_size()` selectively**\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e Example \u003c/th\u003e\u003cth\u003e Expanded example \u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```rust,ignore\n#[derive(HeapSize)]\nstruct Foo {\n    a: usize,\n    b: Option\u003cu64\u003e,\n    #[heap_size]\n    c: Box\u003c[usize; 5]\u003e,\n    #[heap_size]\n    d: Vec\u003cusize\u003e,\n}\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```rust,ignore\nimpl HeapSize for Foo {\n    fn heap_size(\u0026self) -\u003e usize {\n        self.c.heap_size() + self.d.heap_size()\n    }\n}\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- End **Calculate `heap_size()` selectively** --\u003e\n\n\u003c!-- Begin **Calculate `heap_size()` of all fields** --\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCalculate \u003ccode\u003eheap_size()\u003c/code\u003e of all fields\u003c/b\u003e\u003c/summary\u003e\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e Example \u003c/th\u003e\u003cth\u003e Expanded example \u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```rust,ignore\n#[derive(HeapSize)]\n#[heap_size]\nstruct Foo {\n    a: usize,\n    b: Option\u003cu64\u003e,\n    c: Box\u003c[usize; 5]\u003e,\n    d: Vec\u003cusize\u003e,\n}\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```rust,ignore\nimpl HeapSize for Foo {\n    fn heap_size(\u0026self) -\u003e usize {\n        self.a.heap_size()\n            + self.b.heap_size()\n            + self.c.heap_size()\n            + self.d.heap_size()\n    }\n}\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\n\u003c!-- End **Calculate `heap_size()` of all fields** --\u003e\n\n\u003c!-- Begin **Skip irrelative fields** --\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eSkip irrelative fields\u003c/b\u003e\u003c/summary\u003e\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e Example \u003c/th\u003e\u003cth\u003e Expanded example \u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```rust,ignore\n#[derive(HeapSize)]\n#[heap_size]\nstruct Foo {\n    a: usize,\n    b: Option\u003cu64\u003e,\n    #[heap_size(skip)]\n    c: Arc\u003c[usize; 5]\u003e,\n    d: Vec\u003cusize\u003e,\n}\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```rust,ignore\nimpl HeapSize for Foo {\n    fn heap_size(\u0026self) -\u003e usize {\n        self.a.heap_size()\n            + self.b.heap_size()\n            + self.d.heap_size()\n    }\n}\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\n\u003c!-- End **Skip irrelative fields** --\u003e\n\n\u003c!-- Begin **Implement HeapSize for third-party struct** --\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eImplement HeapSize for third-party structs\u003c/b\u003e\u003c/summary\u003e\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e Example \u003c/th\u003e\u003cth\u003e Expanded example \u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```rust,ignore\nmod bytes_heap_size {\n    pub heap_size(\n        b: \u0026Bytes\n    ) -\u003e usize {\n        b.len()\n    }\n}\n\n#[derive(HeapSize)]\n#[heap_size]\nstruct Foo {\n    a: usize,\n    b: Option\u003cu64\u003e,\n    c: Box\u003c[usize; 5]\u003e,\n    d: Bytes,\n}\n```\n\n\u003c/td\u003e\u003ctd\u003e\n\n```rust,ignore\nimpl HeapSize for Foo {\n    fn heap_size(\u0026self) -\u003e usize {\n        self.a.heap_size()\n            + self.b.heap_size()\n            + bytes_heap_size::heap_size(\u0026self.d)\n    }\n}\n```\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\n\u003c!-- End **Implement HeapSize for third-party struct** --\u003e\n\n## `#[derive(HeapSize)]`\n\n### Field attributes\n\nApply to one field in a struct or in an enum variant.\n\n* `#[heap_size]`\n\n  By default, `#[derive(HeapSize)]` generates an empty implementation which\n  always return 0. `#[heap_size]` needs to be added to fields that have a heap\n  allocation.\n\n  This is because of 1) most struct does not contain heap allocation at all,\n  and 2) they often do not implement the `HeapSize` trait.\n\n* `#[heap_size(skip)]`\n\n  Skip this field: do not calculate its heap size.\n\n  Requires a struct has a container attribute `#[heap_size]`.\n\n* `#[heap_size(with = \"module\")]`\n\n  `#[derive(HeapSize)]` will use `$module::heap_size` as the function to obtain\n  this field’s heap size.\n\n### Container attributes\n\nApply to a struct or enum declaration.\n\n* `#[heap_size]`\n  By default, `#[derive(HeapSize)]` generates an empty implementation that\n  always return 0. By adding `#[heap_size]`, it sums up `heap_size()` of all\n  fields in a struct or an enum.\n\n### Variant attributes\n\nApply to a variant of an enum.\n\n* `#[heap_size]`\n\n  Generate\n  By default, `#[derive(HeapSize)]` generates an empty implementation which\n  always return 0. By adding `#[heap_size]`, it sums up `heap_size()` of fields\n  in a variant.\n\n* `#[heap_size(skip)]`\n\n  Skip this variant: do not calculate its heap size.\n\n  Requires an enum has a `#[heap_size]` container attribute.\n\n## License\n\nThis project is licensed under the [MIT license](https://github.com/overvenus/heapsz/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovervenus%2Fheapsz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovervenus%2Fheapsz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovervenus%2Fheapsz/lists"}