it’s possible to work around the “bounds with different associated types are not considered disjoint” limitation by using a helper trait
thanks to Marin Veršić, author of the disjoint_impls crate for publishing this trick!
playground
rust-lang/rust issue
thanks to Marin Veršić, author of the disjoint_impls crate for publishing this trick!
playground
rust-lang/rust issue
Awful Rust snippets for fun and profit
type-erased generic outparams playground
oh, and also I published this one trick as a crate: https://github.com/GoldsteinE/dyngo
implicit use of a trait we’re currently implementing leaks through a module
bonus points to anyone who finds any related documentation (please tell me in the comments if you do!)
playground
thanks to @kanashimia for showing me this
(also yay 200 subscribers!)
bonus points to anyone who finds any related documentation (please tell me in the comments if you do!)
playground
thanks to @kanashimia for showing me this
(also yay 200 subscribers!)
you can access the return type of a macro by unifying it with some variable
playground
playground
postmono const expression conditions
note that you’d also need to do a similar check for alignment, which is omitted for brevity
UPD: as @arjentix pointed out, this will also only work in
playground
note that you’d also need to do a similar check for alignment, which is omitted for brevity
UPD: as @arjentix pointed out, this will also only work in
cargo build
/cargo test
; the check will be skipped in cargo check
playground
a bit late to the party, but couldn’t pass this one
method resolution depends on compiler’s mutable internal state, which you can observe by calling a method on an integer literal
playground
Rust issue (two Zulip threads linked inside)
CI failures for naive fix
method resolution depends on compiler’s mutable internal state, which you can observe by calling a method on an integer literal
playground
Rust issue (two Zulip threads linked inside)
CI failures for naive fix
playground
UCG issue
proposed patch
Awful Rust snippets for fun and profit
my fix for this problem was merged and will be stable in rustc 1.81, unless something goes wrong
https://github.com/rust-lang/rust/pull/123043
https://github.com/rust-lang/rust/pull/123043
GitHub
Disable dead variant removal for `#[repr(C)]` enums. by GoldsteinE · Pull Request #123043 · rust-lang/rust
This prevents removing dead branches from a #[repr(C)] enum (they now get discriminants allocated as if they were inhabited).
Implementation notes: ABI of something like
#[repr(C)]
enum Foo {
F...
Implementation notes: ABI of something like
#[repr(C)]
enum Foo {
F...
match match
is legal and can be occasionally useful- playground
- real-world example from rust-analyzer
- people even do if if sometimes
thanks to @LennyLizowzskiy for suggesting this!
a slightly more fun slash cursed variation on a standard “enum-instead-of-bool” trick
playground
don’t use booleans — an explanation on why would you even want that
thanks to @Ddystopia_0 for inspiring this one!
playground
don’t use booleans — an explanation on why would you even want that
thanks to @Ddystopia_0 for inspiring this one!
parsing sequences (like dates or version strings) by matching on part index
playground
original example
thanks to @kanashimia for suggesting this one!
playground
original example
thanks to @kanashimia for suggesting this one!
1.80 now warns on
playground
release notes about the warning
(also yay 300 subscribers!)
#[cfg(skip)]
, so here’s a workaroundplayground
release notes about the warning
(also yay 300 subscribers!)
wrote down some thoughts about error handling, specifically a pattern that I call “progress pattern” (probably it has another name somewhere, but I’m not aware of it)
https://github.com/GoldsteinE/gh-blog/blob/master/error_progress/README.md
thanks to @meowaffle for reviewing this!
(btw, are y’all ok with breaking the format like this sometimes?)
https://github.com/GoldsteinE/gh-blog/blob/master/error_progress/README.md
thanks to @meowaffle for reviewing this!
(btw, are y’all ok with breaking the format like this sometimes?)
iex by @purplesyringa automatically adds its attribute to the docs by injecting a
code link
<style>
tagcode link
Awful Rust snippets for fun and profit
iex by @purplesyringa automatically adds its attribute to the docs by injecting a <style> tag code link
check out the crate btw, it’s really cool
blog post
blog post
purplesyringa's blog
You might want to use panics for error handling
Rust’s approach to error handling comes at a cost. The Result type often doesn’t fit in CPU registers, and callers of fallible functions have to check whether the returned value is Ok or Err. That’s a stack spill, a comparison, a branch, and a lot of error…