r/rustjerk • u/wai_yu_do_dis • Jan 07 '22
Someone teach him how to write bad code in Rust
55
u/lmao_no_generics Jan 07 '22
The dude is going through first stages of grief. Just check his twitter in a year or so.
14
54
u/bascule Jan 07 '22
Lifetime problems? Why not Clone?
Clone not doing the trick? Use unsafe and turn those lifetimes into pointers!
Pointer provenance got you down? Turn those pointers into usize and back!
Miss global variables? pub static mut is a thing!
13
u/Lich_Hegemon Jan 07 '22
Pointer provenance got you down? Turn those pointers into usize and back!
Not like that, no
83
u/Ahajha1177 Jan 07 '22
Just wrap everything in unsafe, work like RAII was never invented, ignore common rust patterns, etc.
Basically, just write C, but in Rust. I think there's even a crate that lets you skirt around the borrow checker.
48
3
Jan 07 '22
That was pretty much how I initially learned Rust, minus the unsafe bit.
Clippy carried me the rest of the way.
4
u/fullouterjoin &mut self Jan 07 '22
Here is Clippy carrying you to the borrow checker https://upload.wikimedia.org/wikipedia/en/e/ea/Queen_News_Of_The_World.png
15
10
6
u/olsonexi Jan 24 '22
use you_can;
#[you_can::turn_off_the_borrow_checker]
fn main() {
unsafe {
// code goes here
}
}0
Jan 07 '22
[deleted]
11
u/Snakehand all comments formally proven with coq Jan 07 '22
Actually heard from a Rust programmer : I am to bad of a programmer to be writing C, therefore I chose Rust.
3
3
u/Rusty_devl Jan 16 '22
I've been using c++ in the past, but moved to Rust more than one year ago. Recently I pinged a friend to look at like 5 loc in C++, just to tell me if the transposing of a matrix there is causing some aliasing issue since the Eigen documentation had some warnings on that and I was getting strange issues. It's probably good that (hopefully) nobody will ever use C++ code I wrote.
120
u/maroider Jan 07 '22
If the type doesn't fit, use
mem::transmuteso it does.