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
Explore this link on the map →related reading
- A half-hour to learn Rustfasterthanli.me
- Rust Language Cheat Sheetcheats.rs
- Programming a Guessing Game - The Rust Programming Languagedoc.rust-lang.org
- Rewriting Bun in Rust | Bun Blogbun.com
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- What is Ownership? - The Rust Programming Languagedoc.rust-lang.org
- Tristan's Site - Tristan Humethume.ca
- Variables and Mutability - The Rust Programming Languagedoc.rust-lang.org
- Macros - The Rust Programming Languageweb.mit.edu
- Writing an OS in Rustos.phil-opp.com
- Patterns for Defensive Programming in Rust | corrode Rust Consultingcorrode.dev
- The Slice Type - The Rust Programming Languagedoc.rust-lang.org