{"id":28589616,"url":"https://github.com/fast/stacksafe","last_synced_at":"2025-06-12T09:01:49.324Z","repository":{"id":297587589,"uuid":"997253127","full_name":"fast/stacksafe","owner":"fast","description":"Safe execution of deeply recursive functions with automatic stack management.","archived":false,"fork":false,"pushed_at":"2025-06-06T08:24:20.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-06T09:25:42.782Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fast.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,"zenodo":null}},"created_at":"2025-06-06T08:01:12.000Z","updated_at":"2025-06-06T09:14:41.000Z","dependencies_parsed_at":"2025-06-06T09:36:15.609Z","dependency_job_id":null,"html_url":"https://github.com/fast/stacksafe","commit_stats":null,"previous_names":["fast/stacksafe"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fstacksafe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fstacksafe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fstacksafe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fstacksafe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fast","download_url":"https://codeload.github.com/fast/stacksafe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fast%2Fstacksafe/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259227958,"owners_count":22824904,"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-06-11T08:10:39.708Z","updated_at":"2025-06-11T08:10:42.388Z","avatar_url":"https://github.com/fast.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StackSafe\n\n[![Crates.io](https://img.shields.io/crates/v/stacksafe.svg?style=flat-square\u0026logo=rust)](https://crates.io/crates/stacksafe)\n[![Documentation](https://img.shields.io/docsrs/stacksafe?style=flat-square\u0026logo=rust)](https://docs.rs/stacksafe/)\n[![MSRV 1.80.0](https://img.shields.io/badge/MSRV-1.80.0-green?style=flat-square\u0026logo=rust)](https://www.whatrustisit.com)\n[![CI Status](https://img.shields.io/github/actions/workflow/status/fast/stacksafe/ci.yml?style=flat-square\u0026logo=github)](https://github.com/fast/stacksafe/actions)\n\nStackSafe prevents stack overflows in deeply recursive algorithms by providing intelligent stack management. No more crashes from recursive functions or data structures that exceed the default stack size - StackSafe automatically allocates additional stack space when needed, eliminating the need for manual stack size tuning or complex refactoring to iterative approaches.\n\n## Quick Start\n\nAdd StackSafe to your `Cargo.toml`:\n\n```toml\n[dependencies]\nstacksafe = \"0.1\"\n```\n\nTransform recursive functions with the `#[stacksafe]` attribute to prevent stack overflow:\n\n```rust\nuse stacksafe::stacksafe;\n\n#[stacksafe]\nfn fibonacci(n: u64) -\u003e u64 {\n    match n {\n        0 | 1 =\u003e n,\n        _ =\u003e fibonacci(n - 1) + fibonacci(n - 2),\n    }\n}\n\n// No stack overflow, even for deep recursion\nprintln!(\"Fibonacci of 30: {}\", fibonacci(30));\n```\n\n## Recursive Data Structures\n\nUse `StackSafe\u003cT\u003e` to wrap recursive data structures and prevent stack overflow during traversal:\n\n```rust\nuse stacksafe::{stacksafe, StackSafe};\n\n#[derive(Debug, Clone)]\nenum BinaryTree {\n    Leaf(i32),\n    Node {\n        value: i32,\n        left: StackSafe\u003cBox\u003cBinaryTree\u003e\u003e,\n        right: StackSafe\u003cBox\u003cBinaryTree\u003e\u003e,\n    },\n}\n\n#[stacksafe]\nfn tree_sum(tree: \u0026BinaryTree) -\u003e i32 {\n    match tree {\n        BinaryTree::Leaf(value) =\u003e *value,\n        BinaryTree::Node { value, left, right } =\u003e {\n            value + tree_sum(left) + tree_sum(right)\n        }\n    }\n}\n```\n\n## How It Works\n\n- `#[stacksafe]` attribute monitors remaining stack space at function entry points. When available space falls below a threshold (default: 128 KiB), it automatically allocates a new stack segment (default: 2 MiB) and continues execution.\n\n- `StackSafe\u003cT\u003e` is a wrapper type that transparently implement common traits like `Clone`, `Debug`, and `PartialEq` with `#[stacksafe]` support, allowing you to use it in recursive data structures without losing functionality.\n\n## Configuration\n\nCustomize stack management behavior:\n\n```rust\nuse stacksafe::{set_minimum_stack_size, set_stack_allocation_size};\n\n// Trigger allocation when \u003c 64 KiB remaining (default: 128 KiB).\nset_minimum_stack_size(64 * 1024);\n\n// Allocate 4 MiB stacks for deep recursion (default: 2 MiB).\nset_stack_allocation_size(4 * 1024 * 1024);\n```\n\n## Feature Flags\n\nStackSafe supports several optional features:\n\n- `serde`: Provides stack-safe serialization and deserialization for `StackSafe\u003cT\u003e`.\n- `derive-visitor`: Provides stack-safe visitor pattern implementations for `StackSafe\u003cT\u003e`.\n\n## Platform Support\n\nStackSafe works on all major platforms supported by the [`stacker`](https://crates.io/crates/stacker) crate, including:\n\n- Linux (x86_64, ARM64, others)\n- macOS (Intel, Apple Silicon)  \n- Windows (MSVC, GNU)\n- FreeBSD, NetBSD, OpenBSD\n- And more...\n\n## License\n\nThis project is licensed under the [Apache-2.0](LICENSE) license.\n\n## Acknowledgments\n\nInspired by the the excellent [`recursive`](https://crates.io/crates/recursive) by Orson Peters.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Fstacksafe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffast%2Fstacksafe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffast%2Fstacksafe/lists"}