7

Is life too short to fight Rust's borrow checker?

 2 years ago
source link: https://kerkour.com/life-is-short-rust-borrow-checker
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Is life too short to fight Rust's borrow checker?

Sylvain Kerkour

(Ab)using technology for fun & profit. Creator of Bloom and author of Black Hat Rust.

Is life too short to fight Rust's borrow checker?

Tue, Apr 12, 2022

While solving a not-so-easy lifetime problem in Rust related to async closures, I came to think:

Is life too short to fight the borrow checker?

I mean, don't get me wrong, I love solving problems and the beauty of efficient and correct code, but sometimes, too much is too much.

Rust's price for improved control is the curse of choice:

struct Foo {
  bar: Bar
}

struct Foo<'a> {
  bar: &'a Bar
}

struct Foo<'a> {
  bar: &'a mut Bar
}

struct Foo {
  bar: Box<Bar>
}

struct Foo {
  bar: Rc<Bar>
}

struct Foo {
  bar: Arc<Bar>
}

While in most languages, we would simply:

type Foor struct {
  bar Bar
}

call it a day, finish work early and go to the beach for sunset.

So I'm asking you: Is life too short to fight the borrow checker?

Sunset

1 email / week to learn how to (ab)use technology for fun & profit: Programming, Hacking & Entrepreneurship.
I hate spam even more than you do. I'll never share your email, and you can unsubscribe at any time.

black_hat_rust_cover.svg

Want to learn Rust, Cryptography and Security? Get my book Black Hat Rust!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK