Rust for GDScript Developers
Build on GDScript arrays, dictionaries, Callables and classes to learn Rust ownership, borrowing, enums and traits. Complete 48 multi-file tasks, build a parcel depot and port two GDScript programs.
GDScript and Rust side by side
The same program in GDScript and in Rust, from the lessons of this course.
Output and Comments
GDScript runs script callbacks inside Godot; this standalone example uses SceneTree._init and quits explicitly. Rust starts an executable at fn main. Both examples print one line containing a computed value and a literal hash sign. GDScript uses # for…
GDScript1extends SceneTree2 3func _init():4 print("level:%d # literal" % (2 + 3))5 quit()Rust1fn main() {2 // This line is ignored.3 print!("level:");4 println!("{} # literal", 2 + 3);5}Boolean Conditions
GDScript boolean conversion treats an empty Array as false, so the conditional selects fallback. Rust conditions require bool and do not implicitly convert collections or numeric lengths. Write the intended fact explicitly with is_empty, a comparison, or an…
GDScript1extends SceneTree2 3func _init():4 var items = []5 var chosen = "present" if items else "fallback"6 print(chosen)7 print(true if items else false)8 quit()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
GDScript functions can declare parameter and return types, and return explicitly supplies a result. An untyped function without return yields null. Rust function signatures state their parameter and result types; the final expression can return without a…
GDScript1extends SceneTree2func differs(left: String, right: String) -> bool:3 return left != right4 5func _init():6 print(differs("a", "b"))7 print(differs("a", "a"))8 quit()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
GDScript Array assignment creates another reference to the same container, so reversing through second changes the contents seen through first. Rust Vec has an owner, and assigning it to another binding transfers ownership unless an explicit clone is…
GDScript1extends SceneTree2 3func _init():4 var first = [6, 8]5 var second = first6 second.reverse()7 print(first[0])8 print(is_same(first, second))9 quit()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
GDScript String indexes Unicode characters rather than UTF-8 bytes, and to_utf8_buffer explicitly encodes text into bytes. The first character of éx is é, whose first encoded byte is 195. Rust String stores UTF-8 and str views valid UTF-8 text. Rust integer…
GDScript1extends SceneTree2 3func _init():4 var word = "éx"5 print(word[0])6 print(word.to_utf8_buffer()[0])7 quit()Rust1fn main() {2 let word = "éx";3 println!("{}", word.chars().next().unwrap());4 println!("{}", word.get(0..1).is_none());5}Option and Matching
GDScript Variant can hold null to represent missing data, while typed APIs may need another explicit status representation. Rust Option<T> places presence in the static type using Some and None. Some(0) remains a present value, just as the source explicitly…
GDScript1extends SceneTree2 3func _init():4 var values = [0]5 var first = values[0] if not values.is_empty() else null6 var missing = values[2] if values.size() > 2 else null7 print(first == null)8 print(missing == null)9 quit()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 GDScript Developers for?
For people who already write GDScript and want to learn Rust. Each lesson starts from GDScript 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 GDScript basics: variables, conditions, loops, functions and collections.
How many lessons does Rust for GDScript Developers have?
Rust for GDScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Rust for GDScript 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 GDScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.