Skip to content
Learn Netverks

Lesson

Step 20/36 56% through track

strings-rust

Strings in Rust

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

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

Teams ship Strings in Rust on every Rust codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Strings in Rust 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.

Rust has String (owned, growable UTF-8) and &str (borrowed slice). String literals are &'static str. Indexing by byte can panic—use chars or graphemes for Unicode.

Building strings

let mut s = String::from("Hello");
s.push_str(", Rust!");

Important interview questions and answers

  1. Q: Why not index String like an array of chars?
    A: UTF-8 is variable-width—byte index may split a character.

Self-check

  1. Owned vs borrowed string types?
  2. Are Rust strings UTF-8?

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.

Discussion

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

Starter discussion topics

  • str vs String?
  • UTF-8 indexing trap?

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