mishra.farm -- party tricks to show off your esoteric rust knowledge
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
related reading
- A half-hour to learn Rustfasterthanli.me
- Rust Language Cheat Sheetcheats.rs
- Rewriting Bun in Rust | Bun Blogbun.com
- Programming a Guessing Game - The Rust Programming Languagedoc.rust-lang.org
- Learn Rust the Dangerous Waycliffle.com
- GitHub - knurling-rs/flip-link: Adds zero-cost stack overflow protection to your embedded programsgithub.com
- Measure What You Optimizecliffle.com
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- What is Ownership? - The Rust Programming Languagedoc.rust-lang.org
- Variables and Mutability - The Rust Programming Languagedoc.rust-lang.org
- Writing an OS in Rustos.phil-opp.com
- Macros - The Rust Programming Languageweb.mit.edu