Menu
CoddyTech
Course

Rust for Dart Developers

Move from Dart classes, nullable values, and lazy iterables to Rust ownership, borrowing, enums, and traits. Complete 48 multi-file lessons, build a parcel depot, and port two Dart programs.

Dart and Rust side by side

The same program in Dart and in Rust, from the lessons of this course.

  1. Output and Comments

    Dart print converts its argument to text and writes a newline. Rust println! checks a formatting expression and its arguments during compilation. Both languages support line and block comments, but Rust's exclamation mark identifies a macro rather than an…

    Dart
    1void main() {2  final ready = 2 < 5;3  // The label is part of the output contract.4  print('ready=' + ready.toString());5}
    Rust
    1fn main() {2    let ready: bool = 2 < 5;3    // The label is part of the output contract.4    println!("ready={}", ready);5}
  2. Boolean Conditions

    Dart and Rust both require boolean conditions. An empty string is not automatically false in either language, so test isEmpty or is_empty explicitly. Dart's ?? operator selects a fallback only for null; an existing empty string remains a value. Rust ordinary…

    Dart
    1void main() {2  final label = '';3  final chosen = label.isEmpty ? 'fallback' : label;4  print(chosen == 'fallback');5}
    Rust
    1fn main() {2    let label = "";3    let missing = label.is_empty();4    let same = "fallback" == "fallback";5    println!("{}", missing && same);6}
  3. Functions and Returns

    Dart arrow functions return the value of their single expression, while block-bodied Dart functions use return for an explicit result. Rust functions declare parameter types and a return type after an arrow; the final unterminated expression can supply the…

    Dart
    1bool invert(bool value) => !value;2void main() { print(invert(false)); }
    Rust
    1fn invert(value: bool) -> bool { !value }2fn main() { println!("{}", invert(false)); }
  4. Ownership and Moves

    Assigning a Dart class instance to another variable creates another reference to the same object. The example mutates through alias and reads the change through original; final on those bindings does not freeze the Draft. Rust assignment of a non-Copy String…

    Dart
    1class Draft {2  String text;3  Draft(this.text);4}5void main() {6  final original = Draft('draft');7  final alias = original;8  alias.text = 'ready';9  print(original.text);10}
    Rust
    1fn main() {2    let original = String::from("ready");3    let owner = original;4    println!("{}", owner);5}
  5. Strings and UTF-8

    Dart String indexes UTF-16 code units and exposes Unicode code points through runes. Rust str and String contain UTF-8 and expose scalar values through chars. These examples use the appropriate decoding iterator to print A and the emoji as separate lines.…

    Dart
    1void main() {2  for (final scalar in 'A😀'.runes) {3    print(String.fromCharCode(scalar));4  }5}
    Rust
    1fn main() {2    for scalar in "A😀".chars() {3        println!("{}", scalar);4    }5}
  6. Option and Matching

    Dart expresses optional values with nullable types and uses ?? to select a fallback for null. Rust Option has explicit Some and None variants, keeping absence distinct from zero, false, or empty text. Dart list indexing throws outside the valid range, so the…

    Dart
    1void main() {2  final samples = [0, 8];3  const index = 5;4  final int? value = index < samples.length ? samples[index] : null;5  print(value ?? 99);6}
    Rust
    1fn main() {2    let samples = [0, 8];3    let value = samples.get(5);4    println!("{}", match value { Some(n) => *n, None => 99 });5}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Dart developers

Learn Rust from another language

Frequently asked questions

Who is Rust for Dart Developers for?

For people who already write Dart and want to learn Rust. Each lesson starts from Dart you know and shows how Rust does the same thing, so you skip the beginner basics.

Do I need to know Rust already?

No. The course starts with your first Rust program. You need Dart basics: variables, conditions, loops, functions and collections.

How many lessons does Rust for Dart Developers have?

Rust for Dart Developers contains 48 interactive lessons you can complete at your own pace.

What does Rust for Dart Developers cover?

The course is organized into chapters covering: First Rust Programs, Decisions and Loops, Functions and Sequences, Ownership and Borrowing, and more.

Is Rust for Dart Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Rust for Dart Developers for free

Get started