Thanh Hương 🎩🎭
@thanhhuong
Question for Rustaceans. I am trying to understand something about detecting dead code in Rust so I put together an example to have something to reason about. These 2 code snippets achieve a similar result in Rust and TS. In TS the string is narrowed down to its value (i.e. \`Bob\`) so the TS code produce a compiler error which allows to detect and remove dead code. While the Rust one, although formally correct, does not produce a compiler error (although the compiler could still perform a dead code removal operation on the final binary), leaving the source code with a code branch that will never be exercised. Is there a way to achieve something similar in Rust? Would it require an enum necessarily? https://ik.imagekit.io/lens/media-snapshot/281e044dbbe5f2bfb19a74bcf8bfc60eb93c1876e9b6c16c4f6add34298cd271.png
0 reply
0 recast
0 reaction