TGViewer
Блог* Блог* @dereference_pointer_there · 1.98K subscribers
Post #10352 800

Forwarded from Random Rust Dev

Плохие советы для краболюдов.

Часто бывает так, что в функции, которая принимает self нужно вызвать функцию, которая принимает &mut self.
fn final(self) {
self.mutating_foo(); ❌
}


Есть очевидный способ это сделать - объявить аргумент как мутируемым.
Для вызывающего кода это ни на что не влияет.
fn final(mut self) {
self.mutating_foo(); ✅
}


Или (менее популярно) перебиндить в теле функции
fn final(self) {
let mut me = self;
me.mutating_foo(); ✅
}


Но есть способ для того что бы инкрементить WTF_COUNT у читателя.

fn final(self) {
{ self }.mutating_foo(); 💀
}
  • 🤯 23
  • 😢 17
More from @dereference_pointer_there
  1. Oct 16, 2026Тем временем разработчики на Go *tailscale
  2. Oct 16, 2026А всем остальным нам?!
  3. Oct 16, 2026#meme про сон
  4. Oct 15, 2026#prog #rust #suckassstory rustc uses the Path hash code to identify files, and the Path ha…
  5. Oct 15, 2026#python #meme
  6. Oct 14, 2026r/rust (потому что написано вроде на Tauri)
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →