flâneur — a map of the web's best reading

mishra.farm -- party tricks to show off your esoteric rust knowledge

mishra.farm · 755 words · saved by 1 readers

My friend Sasha asked for some Rust party tricks, so here are a few that I remember off of the top of my head. This one was on reddit a while ago. The trick is that you can open /proc/self/mem as a file to freely edit process memory without unsafe. I learned this from Lachlan. Putting a const-context panic inside a function's Drop implementation means that dropping it (e.g with drop or by letting it fall out of scope) will emit a compile error. The only way to 'get rid' of such a value is by std::mem::forget. This only works for generic types, since the const expression is evaluated per monomorphization. The typical tool of choice for generating nontrivial amounts of code at compile time are proc macros. However, I did come across another method in the wild that works if you don't need to consume any AST tokens from the actual site of use: dynamically generating code at build time in the build.rs script, and using include! to include the generated code verbatim in the crate source. Thi

motivation My friend Sasha asked for some Rust party tricks, so here are a few that I remember off of the top of my head. totally-safe-transmute This one was on reddit a while ago. The trick is that you can open /proc/self/mem as a file to freely edit process memory without unsafe . undroppable types I learned this from Lachlan. Putting a const -context panic inside a function's Drop implementation means that dropping it (e.g with drop or by letting it fall out of scope) will emit a compile error. The only way to 'get rid' of such a value is by std::mem::forget . This only works for generic ty

Explore this link on the map →

related reading