FP Complete

Rust’s as_ref vs as_deref

What’s wrong with this program? fn main() { let option_name: Option<String> = Some(“Alice”.to_owned()); match option_name { Some(name) => println!(“Name is {}”, name), None => println!(“No name provided”), } println!(“{:?}”, option_name); } The compiler gives us a wonderful error message, including a hint on how to fix it: error[E0382]: borrow of partially moved value: `option_name` –> […]

Cloning a reference and method call syntax in Rust

This semi-surprising corner case came up in some recent Rust training I was giving. I figured a short write-up may help some others in the future. Rust’s language design focuses on ergonomics. The goal is to make common patterns easy to write on a regular basis. This overall works out very well. But occasionally, you […]