3 ms·
C is a language without much of a standard library. To do this in C you'd first need to write a coroutine library. In Rust, your approach sounds fine. However
by kccqzy 3y ago
C is a language without much of a standard library. To do this in C you'd first need to write a coroutine library.
In Rust, your approach sounds fine. However you should also consider simply using Rust's iterator. Define a struct containing the state you want, then implement it as an Iterator. In the future, you can also just write control flow and have the compiler transform that for you. Take a look at the first few sections of https://lang-team.rust-lang.org/design_notes/general_coroutines.html https://lang-team.rust-lang.org/design_notes/general_corouti...