Rust Learning Log

Ownership Finally Clicked a Little More

A short checkpoint on what ownership started to mean once I stopped reading it as magic and started reading it as explicit responsibility.

Topic: Ownership Status: Sticky enough to reuse ownershipborrowingbasics

Rust started making more sense when I stopped treating ownership like a special language trick and started treating it like a strict rule about who is responsible for a value right now.

What clicked

  • A move is Rust refusing to let two parts of the program pretend they both fully control the same value.
  • String moves because it owns heap data.
  • Plain integers feel easier because copying them is cheap and unambiguous.

What I want to remember

If a function takes String, I should assume it is allowed to keep it.

If I only want to inspect something, I probably want &str or &String instead.

fn print_name(name: &str) {
	println!("{name}");
}

fn main() {
	let name = String::from("Ferris");
	print_name(&name);
	println!("still mine: {name}");
}

What still feels easy to mess up

I still have to pause and ask whether I want to transfer ownership, borrow temporarily, or clone because I am avoiding the real decision.

That pause is probably the point.

Back to Rust log