Rust for Swift Developers
Move from Swift value types, optionals, protocols and ARC to Rust ownership, borrowing, enums and traits. Complete 48 multi-file lessons, build a parcel depot and port two Swift programs.
Swift and Rust side by side
The same program in Swift and in Rust, from the lessons of this course.
Output and Comments
Swift console programs can execute top-level statements, while a Rust executable starts at fn main. Both languages use slash comments and leave a hash inside quoted text as data. Swift string interpolation uses a parenthesized expression after a backslash…
Swift1// This line is a comment.2print("level:", terminator: "")3print("\(2 + 3) # literal")Rust1fn main() {2 // This line is ignored.3 print!("level:");4 println!("{} # literal", 2 + 3);5}Boolean Conditions
Swift and Rust require Boolean conditions rather than converting zero or an empty collection into false. Test isEmpty or is_empty explicitly when deciding whether an element exists. Both languages short-circuit &&, so the right-hand index is skipped when the…
Swift1let items: [Int] = []2let present = !items.isEmpty3print(present)4print(present && items[0] > 0)Rust1fn main() {2 let items: Vec<i32> = Vec::new();3 let present = !items.is_empty();4 println!("{}", present);5 println!("{}", present && items[0] == 9);6}Functions and Returns
Swift and Rust declare function input and output types. Swift argument labels are part of call syntax, while Rust ordinary positional calls do not use them. Swift permits implicit returns for single-expression functions, and Rust uses the final expression…
Swift1func differs(_ left: Character, _ right: Character) -> Bool {2 return left != right3}4print(differs("a", "b"))5print(differs("a", "a"))Rust1fn differs(left: char, right: char) -> bool { left != right }2fn main() {3 println!("{}", differs('a', 'b'));4 println!("{}", differs('a', 'a'));5}Ownership and Moves
Swift Array and String have value semantics, often implemented with copy-on-write storage sharing. Reassigning or mutating an independent array value preserves the original logical value, as the source demonstrates. Swift class instances instead have…
Swift1let first = [6, 8]2var second = first3second.reverse()4print(first[0])5print(second[0])Rust1fn main() {2 let first = vec![6, 8];3 let mut second = first;4 second.reverse();5 let mut independent = second.clone();6 independent.clear();7 println!("{}", second[0]);8 println!("{}", independent.len());9}Strings and UTF-8
Swift String is traversed with String.Index and its Character elements represent extended grapheme clusters. Its unicodeScalars and utf8 views expose different units. Rust chars yields Unicode scalar values, not grapheme clusters, and bytes yields UTF-8…
Swift1let word = "éx"2print(word.first!)3print(word.utf8.first!)Rust1fn main() {2 let word = "éx";3 println!("{}", word.chars().next().unwrap());4 println!("{}", word.get(0..1).is_none());5}Option and Matching
Swift Optional<T> and Rust Option<T> both distinguish a present value from absence, including a present zero or false. Swift Array ordinary subscripting is not optional, so the source checks indices before returning nil for a missing position. Rust get…
Swift1let values = [0]2func at(_ index: Int) -> Int? {3 values.indices.contains(index) ? values[index] : nil4}5print(at(0) == nil)6print(at(2) == nil)Rust1fn main() {2 let values = vec![0];3 println!("{}", values.get(0).is_none());4 println!("{}", values.get(2).is_none());5}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Rust Programs
6 lessonsDecisions and Loops
5 lessonsFunctions and Sequences
4 lessonsOwnership and Borrowing
5 lessonsText and Collections
4 lessonsAbsence and Failure
5 lessonsStructs and State
6 lessonsTraits and Generic Code
7 lessonsProject: Parcel Depot
4 lessonsFinal Ports
2 lessonsFrequently asked questions
Who is Rust for Swift Developers for?
For people who already write Swift and want to learn Rust. Each lesson starts from Swift 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 Swift basics: variables, conditions, loops, functions and collections.
How many lessons does Rust for Swift Developers have?
Rust for Swift Developers contains 48 interactive lessons you can complete at your own pace.
What does Rust for Swift 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 Swift Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.