Skip to content
Learn Netverks

Lesson

Step 13/36 36% through track

moves-borrows

Moves and borrows

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Moves and borrows: the syntax, APIs, and habits you need before advancing in Rust.

Ownership is Rust’s defining idea—interviewers ask you to explain moves, borrows, and why the compiler rejects dangling pointers.

You will apply Moves and borrows in contexts like: Infrastructure CLIs, proxies, game engines, blockchain nodes, and latency-sensitive backends.

Write Rust with fn main(), click Run on server—the dev runner compiles main.rs with rustc and runs the binary; fix borrow errors from stderr (requires Rust toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Assigning a non-Copy value moves ownership—the source becomes invalid. Borrowing lets you use data without taking ownership via references.

Move example

let a = String::from("x");
let b = a; // a moved; println!("{}", a) errors

Borrowing preview

let s = String::from("hello");
let len = s.len(); // s still valid—no move

Important interview questions and answers

  1. Q: Move vs shallow copy?
    A: Move invalidates the source; Copy types duplicate bits without invalidating.
  2. Q: Why moves exist?
    A: Prevent double-free and use-after-free without GC.

Self-check

  1. What happens to the old variable after a move?
  2. Does calling .len() move a String?

Tip: If you need to keep using a String, borrow with &s or call .clone() explicitly—moves are intentional, not bugs.

Interview prep

Move vs Copy?

Copy types duplicate bits on assignment (e.g. i32); move types transfer ownership and invalidate the source (e.g. String).

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Community stories on this track

Learner essays linked to Rust — not official lesson content.

Browse all stories

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • After move use?
  • Borrow while mut?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump