Skip to content
Learn Netverks

Lesson

Step 24/36 67% through track

traits-basics

Traits basics

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

This lesson

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

Traits are Rust’s abstraction for shared behavior—like interfaces plus generics, enforced at compile time.

You will apply Traits basics 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.

Traits define shared behavior—like interfaces in Java. Implement traits for your types to provide methods expected by generic code or standard library APIs.

Define and implement

trait Summary { fn summarize(&self) -> String; }
impl Summary for News { ... }

Important interview questions and answers

  1. Q: Trait vs interface?
    A: Similar role—Rust traits support default methods, associated types, and static dispatch.

Self-check

  1. What keyword implements a trait?
  2. Can a type implement multiple traits?

Tip: Traits resemble Java interfaces but support default methods and work with generics for static dispatch.

Interview prep

Trait vs interface?

Similar role defining behavior; Rust traits support default methods, associated types, and integrate with generics and trait objects.

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

  • impl Trait where?
  • Default trait?

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