Tailcall is a library that adds safe, zero-cost tail recursion to stable Rust.
Eventually, it will be superseded by the become
keyword.
Tailcall is distributed as a crate.
Add this to your Cargo.toml
:
toml
[dependencies]
tailcall = "0.1"
Add the tailcall
attribute to functions which you would like to use tail recursion:
```rust use tailcall::tailcall;
fn factorial(input: u64) -> u64 { #[tailcall] fn factorialinner(accumulator: u64, input: u64) -> u64 { if input > 0 { factorialinner(accumulator * input, input - 1) } else { accumulator } }
factorial_inner(1, input)
} ```
For more detailed information, please see the docs.
Development dependencies, testing, documentation generation, packaging, and distribution are all managed via Cargo.
After checking out the repo, run cargo test
to verify the test suite.
The latest documentation can be generated with cargo doc
.
Before commiting, please make sure code is formatted canonically with cargo fmt
.
New versions are released to crates.io with cargo publish
.
Bug reports and pull requests are welcome on GitHub.
Tailcall is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.