Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Rust tells: unwrap, clone and RefCell to appease the compiler
card 6 of 6
Ask what the clean compile was bought with
builds on: Silencing the checker: type escapes and suppressions, Error handling idioms across languages
In Rust, a build made to pass with `.unwrap()`, `.clone()`, `Rc<RefCell<_>>` or `Arc<Mutex<_>>` often just moves the error to run time. It comes back as a panic, a runtime borrow failure, a deadlock, or an edit on a copy. For each one, ask three things. Can it fail here? Does the copy need writing back? Who should own this data?
Terms on this card
- .unwrap()
- Rust method on Option/Result that returns the inner value, or panics if it is None or Err.
- .clone()
- Makes an independent copy of a value. Changes to the copy don't affect the original. For Rc/Arc it only copies the pointer.
- panic
- Rust's unrecoverable error. It unwinds and ends the current thread; in main, the whole program exits.
- Rc<RefCell<_>>
- Rc gives shared ownership on one thread. RefCell allows mutation through a shared handle, checking borrow rules at run time and panicking on overlap.
- Arc<Mutex<_>>
- Arc gives shared ownership across threads. Mutex lets one thread at a time access the data through a lock guard.
Lesson goal: Recognise Rust-specific shortcuts: `.unwrap()`/`.expect()` on fallible paths, `.clone()` scattered to dodge borrow errors, and `Rc<RefCell<_>>` or `Arc<Mutex<_>>` used where ownership needed redesigning. Explain the panics and runtime borrow failures these trade for a clean compile. ·
the whole lesson