Implementing our own fibers
Before we start, I want to make sure you understand that the code we write is quite unsafe and is not a “best practice” when writing Rust. I want to try to make this as safe as possible without introducing a lot of unnecessary complexity, but there is no way to avoid the fact that there will be a lot of unsafe code in this example. We will also prioritize focusing on how this works and explain it as simply as possible, which will be enough of a challenge in and of itself, so the focus on best practices and safety will have to take the back seat on this one.
Let’s start off by creating a whole new project called c-fibers
and removing the code in main.rs
so we start with a blank sheet.
Note
You will also find this example in the repository under the ch05/c-fibers
folder. This example, as well as ch05/d-fibers-closure
and
ch05/e-fibers-windows
, needs to be compiled using the nightly compiler since we use an unstable feature. You...