Menu
CoddyTech
Course

Swift for Rust Developers

Move from Rust to Swift through value semantics, optionals, Unicode text, protocols and ARC. Complete 48 multi-file exercises, build a parcel desk across four steps and port two complete Rust programs.

Rust and Swift side by side

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

  1. Bindings and Mutation

    Rust bindings are immutable by default, and mut permits changing a binding or mutating its owned value through the appropriate API. Assigning a Vec normally moves ownership; clone explicitly duplicates its elements. Swift let and var choose binding…

    Rust
    1
    2fn main() {3    let original = vec![2, 4];4    let mut copy = original.clone();5    copy.push(6);6    println!("{} {}", original.len(), copy.len());7}
    Swift
    1let original = [2, 4]2var copy = original3copy.append(6)4print(original.count, copy.count)
  2. Strings and Interpolation

    Rust str is UTF-8 text and String owns a growable UTF-8 buffer. Methods such as starts_with and repeat express text operations without manual indexing, and format! constructs formatted strings. Swift uses String values, hasPrefix and String(repeating:count:)…

    Rust
    1
    2fn main() {3    let word = "echo";4    println!("{}", word.starts_with("ec"));5    println!("{}", word.repeat(2));6}
    Swift
    1let word = "echo"2print(word.hasPrefix("ec"))3print(String(repeating: word, count: 2))
  3. Switch and Patterns

    Rust match and Swift switch both support exhaustive pattern matching, including tuples, wildcard components and alternatives. The origin case must precede the broader axis alternatives because the origin also lies on an axis. Rust uses | between alternative…

    Rust
    1fn location(x: i32, y: i32) -> &'static str {2    match (x, y) { (0, 0) => "origin", (0, _) | (_, 0) => "axis", _ => "plane" }3}4
    5fn main() {6    println!("{}", location(0, 0));7    println!("{}", location(0, 5));8    println!("{}", location(2, 3));9}
    Swift
    1func location(_ x: Int, _ y: Int) -> String {2    switch (x, y) {3    case (0, 0): return "origin"4    case (0, _), (_, 0): return "axis"5    default: return "plane"6    }7}8print(location(0, 0))9print(location(0, 5))10print(location(2, 3))
  4. Functions and Labels

    Rust function arguments are positional. Parameter names help readers of the declaration but do not become call-site labels. Swift distinguishes an external argument label from the local parameter name, and _ suppresses the first label. The target calls…

    Rust
    1fn greet(person: &str, sender: &str) -> String { format!("{} greets {}", sender, person) }2
    3fn main() {4    println!("{}", greet("Mina", "Jo"));5}
    Swift
    1func greet(_ person: String, from sender: String) -> String {2    return "\(sender) greets \(person)"3}4print(greet("Mina", from: "Jo"))
  5. Dictionaries and Missing Keys

    Rust HashMap::get returns Option<&V>, borrowing a stored value when present. Copied turns the borrowed integer into an owned integer optional before defaulting. Swift Dictionary lookup returns an Optional value, and its default subscript can supply a fallback…

    Rust
    1
    2fn main() {3    let ages = std::collections::HashMap::from([("Mina", 12)]);4    println!("{}", ages.get("Mina").copied().unwrap_or(-1));5    println!("{}", ages.get("Jo").copied().unwrap_or(99));6    println!("{}", ages.len());7}
    Swift
    1let ages = ["Mina": 12]2print(ages["Mina"] ?? -1)3print(ages["Jo", default: 99])4print(ages.count)
  6. Structs and Independent Copies

    A Rust struct may implement Copy when every component supports it and the type satisfies the trait's restrictions. This Point derives Copy and Clone, so assignment duplicates its integer fields and leaves original usable. A non-Copy Rust struct would normally…

    Rust
    1#[derive(Clone, Copy)]2struct Point { x: i32, y: i32 }3
    4fn main() {5    let original = Point { x: 3, y: 4 };6    let mut reflected = original;7    reflected.x = -reflected.x;8    assert_eq!(original.y, reflected.y);9    println!("{} {}", original.x, reflected.x);10}
    Swift
    1struct Point { var x: Int; let y: Int }2let original = Point(x: 3, y: 4)3var reflected = original4reflected.x = -reflected.x5print(original.x, reflected.x)

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Rust developers

Learn Swift from another language

Frequently asked questions

Who is Swift for Rust Developers for?

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

Do I need to know Swift already?

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

How many lessons does Swift for Rust Developers have?

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

What does Swift for Rust Developers cover?

The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.

Is Swift for Rust 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 Swift for Rust Developers for free

Get started