{"id":27339427,"url":"https://github.com/zeramorphic/flat-drop","last_synced_at":"2025-07-18T08:33:23.619Z","repository":{"id":285750445,"uuid":"959192217","full_name":"zeramorphic/flat-drop","owner":"zeramorphic","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-24T16:29:30.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T16:46:04.672Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeramorphic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-04-02T12:11:35.000Z","updated_at":"2025-06-24T16:29:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"ff753d9f-1a9e-45ad-842e-27d115b7cdcf","html_url":"https://github.com/zeramorphic/flat-drop","commit_stats":null,"previous_names":["zeramorphic/flat-drop"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zeramorphic/flat-drop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeramorphic%2Fflat-drop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeramorphic%2Fflat-drop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeramorphic%2Fflat-drop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeramorphic%2Fflat-drop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeramorphic","download_url":"https://codeload.github.com/zeramorphic/flat-drop/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeramorphic%2Fflat-drop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265728815,"owners_count":23818729,"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":[],"created_at":"2025-04-12T15:53:38.874Z","updated_at":"2025-07-18T08:33:23.611Z","avatar_url":"https://github.com/zeramorphic.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flat drop\n\nIn this crate, we define the `FlatDrop` type.\n`FlatDrop\u003cK\u003e` behaves just like a `K`, but with a custom `Drop` implementation\nthat avoids blowing up the stack when dropping large objects.\nInstead of recursively dropping subobjects, we perform a depth-first search\nand iteratively drop subobjects.\n\nTo use this crate, you can replace recursive `Box`es and `Arc`s in your types\nwith `FlatDrop\u003cBox\u003cT\u003e\u003e` or `FlatDrop\u003cArc\u003cT\u003e\u003e`. You'll need to implement the\n`Recursive` trait for your type, which performs one step of the iterative\ndropping procedure.\n\nThis crate uses `unsafe` internally, but the external API is safe.\n\n# Example\n\n```rs\nuse flat_drop::{FlatDrop, Recursive};\n\n/// Peano natural numbers.\nenum Natural {\n    Zero,\n    Succ(FlatDrop\u003cBox\u003cNatural\u003e\u003e),\n}\n\nimpl Recursive for Natural {\n    type Container = Box\u003cNatural\u003e;\n\n    fn destruct(self) -\u003e impl Iterator\u003cItem = Self::Container\u003e {\n        match self {\n            Natural::Zero =\u003e None,\n            Natural::Succ(pred) =\u003e Some(pred.into_inner()),\n        }\n        .into_iter()\n    }\n}\n\nimpl Natural {\n    pub fn from_usize(value: usize) -\u003e Self {\n        (0..value).fold(Self::Zero, |nat, _| {\n            Self::Succ(FlatDrop::new(Box::new(nat)))\n        })\n    }\n}\n\n// Create a new thread with a 4kb stack and allocate a number far bigger than 4 * 1024.\nconst STACK_SIZE: usize = 4 * 1024;\n\nfn task() {\n    let nat = Natural::from_usize(STACK_SIZE * 100);\n    drop(std::hint::black_box(nat));\n}\n\nstd::thread::Builder::new()\n    .stack_size(STACK_SIZE)\n    .spawn(task)\n    .unwrap()\n    .join()\n    .unwrap();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeramorphic%2Fflat-drop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeramorphic%2Fflat-drop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeramorphic%2Fflat-drop/lists"}