← Back to context

Comment by Arnavion

2 years ago

>You have to implement the C version manually

There's no "manually" about it. There's only one way to implement it in C, ie eight booleans and eight uint8_ts as I described. Going from there to the further optimization of adding a `:1` to every `bool` field is a simple optimization. Reimplementing `Option` and the bitpacking of the discriminants is much more effort compared to the baseline implementation of using `Option`.

The alternative is `std::optional` which works exactly the same as Rust's `Option` (without the niche optimisation).

I'm not a C programmer but I imagine you could make something like `std::optional` in C using structs and macros and whatnot.

But it's not any more work than it would take in C. What does it matter how much work it is relative to rust's happy path?