Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f...
by macgyverismo on Sunday May 05, 2024 @11:03AM
(#40265404)
That matches the 'static_assert' portion of my sample code. The implied claim of the parent I replied to was that rust could do this even for runtime values, such as the one I am using in the main of my sample.
In c++ it is the same function running both the compile time check and the unchecked runtime variant, so there is zero overhead at runtime. I can't possibly think of a way how rust would be able to make the same code in my sample safe without adding runtime checks. If I am mistaken here I sure would like to know.
[ Parent
| on HN ]
Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f...
by umanwizard on Sunday May 05, 2024 @12:32PM
(#40266088)
You’re correct. Rust can’t statically prove which enum variant is inhabited. You do need a runtime switch, the difference is (at least in safe code) it statically forces you to indeed do that runtime switch.
Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f...
by kaashif on Sunday May 05, 2024 @02:33PM
(#40267084)
You aren't mistaken. I should've written "runtime overhead" - my point is that there is no runtime performance penalty for getting rid of the UB in the Option API.
An equivalent API with no UB is just strictly better.