A tiny crate that turns functions into lazy tasks.
Defer any function call — sync or async — until you're ready to run it. One attribute, and a task becomes just a value.
The idea is easy to grasp if you know async — the mechanics are very similar. The #[task] attribute rewrites the function so the call only captures the arguments and returns a task, while the function body is moved into run and executes there.
sync function → Task, run returns the value
async function → AsyncTask, run returns a Send future
Quick Start
use lazydeed::*; #[task] fn sum(x: i32, y: i32) -> i32 { x + y } let task = sum(1, 2); // nothing runs yet // In this case, the function will be called and will output the number 3. println!("{}", task.run()); Async works the same way: mark the function async, get an AsyncTask, and run returns a Send future to await on your own runtime.
Methods are not supported yet.
GitHub: GitHub - Honami333/Lazydeed: A tiny Rust crate that turns functions into lazy tasks: nothing runs until run() · GitHub
Crates.io: crates.io: Rust Package Registry
Telegram: View @cat_garden_news
Glad for any feedback and ideas.
1 post - 1 participant