3 ms·
>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 a
by Arnavion 3y 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`.
- IshKebab 3y agoThe 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.
- surajrmal 3y agoBut 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?