Rust for Luau Developers
Move from Luau typed tables, optional values, and closures to Rust ownership, borrowing, enums, and traits. Complete 48 multi-file lessons, build a parcel depot, and port two Luau programs.
Luau and Rust side by side
The same program in Luau and in Rust, from the lessons of this course.
Output and Comments
Luau executes a compiled chunk and supports optional static annotations, while a Rust executable starts at fn main. Luau line comments use two hyphens; Rust uses slash comments. A marker inside quoted text is data. Luau io.write performs the first write…
Luau1-- This line is ignored.2local value: number = 2 + 33io.write("level:")4print(string.format("%d # literal", value))Rust1fn main() {2 // This line is ignored.3 print!("level:");4 println!("{} # literal", 2 + 3);5}Boolean Conditions
Luau treats only nil and false as falsey. An empty typed table, zero, and an empty string remain truthy, so or selects items rather than fallback. Luau and and or short-circuit and return an operand, which need not be boolean. Rust conditions require bool and…
Luau1local items: {number} = {}2local chosen = items or "fallback"3print(chosen == items)4print(not not items)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
Luau functions can declare parameter and return types, and an explicit return supplies the result. An unannotated function falling off the end returns no values, appearing as nil where a single result is expected. Rust signatures declare types and can return…
Luau1local function differs(left: string, right: string): boolean2 return left ~= right3end4print(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
Luau assigning a typed table creates another reference to the same container; its type annotation does not make the assignment a copy or move. Swapping through second changes what first observes, and rawequal confirms identity. Rust Vec instead has an owner…
Luau1local first: {number} = {6, 8}2local second = first3second[1], second[2] = second[2], second[1]4print(first[1])5print(rawequal(first, second))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
Luau strings store arbitrary bytes and are not inherently guaranteed to contain valid UTF-8. The utf8 library decodes this valid sample to obtain its first Unicode code point, while string.byte returns the first encoded byte. Rust str and String always…
Luau1local word: string = "éx"2print(utf8.char(utf8.codepoint(word, 1)))3print(string.byte(word, 1))Rust1fn main() {2 let word = "éx";3 println!("{}", word.chars().next().unwrap());4 println!("{}", word.get(0..1).is_none());5}Option and Matching
Luau optional types such as number? describe a value that may be nil. Ordinary missing table entries yield nil, while zero remains present and truthy. Rust Option<T> uses explicit Some and None variants, so absence is part of its declared type. The examples…
Luau1local values: {number} = {0}2local first: number? = values[1]3local missing: number? = values[3]4print(first == nil)5print(missing == 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 Luau Developers for?
For people who already write Luau and want to learn Rust. Each lesson starts from Luau 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 Luau basics: variables, conditions, loops, functions and collections.
How many lessons does Rust for Luau Developers have?
Rust for Luau Developers contains 48 interactive lessons you can complete at your own pace.
What does Rust for Luau 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 Luau Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.