Menu
CoddyTech
Course

Rust for Kotlin Developers

Move from Kotlin nullable types, classes and lambdas to Rust ownership, borrowing, traits and explicit errors. Complete 48 multi-file tasks, build a parcel depot, and port two Kotlin applications.

Kotlin and Rust side by side

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

  1. Output and Comments

    Kotlin permits a top-level main function, so an explicit enclosing class is unnecessary. Rust also begins at a free fn main. Both languages support line comments and block comments, and comment markers inside a quoted string remain data. Kotlin compiles this…

    Kotlin
    1fun main() {2    // Addition starts after a string has already been produced.3    println("sum=" + 2 + 3)4}
    Rust
    1fn main() {2    // Addition is evaluated before formatting.3    println!("sum={}", 2 + 3);4}
  2. Boolean Conditions

    Kotlin and Rust conditions require boolean values; neither treats an integer or collection as a truth value. Both use && and || with short-circuit evaluation, and ! negates a boolean. The right operand of || is skipped when the left is true, while the right…

    Kotlin
    1fun main() {2    val divisor = 03    val bypass = divisor == 0 || 12 / divisor > 24    println(bypass)5}
    Rust
    1fn main() {2    let divisor: i32 = 0;3    let bypass = divisor == 0 || 12 / divisor > 2;4    println!("{}", bypass);5}
  3. Functions and Returns

    Kotlin supports top-level functions as well as class members, and expression-bodied functions return their expression value. Rust free functions similarly live in modules and declare parameter types and a result type after ->. A final unterminated expression…

    Kotlin
    1fun swap(a: Int, b: Int): Pair<Int, Int> = b to a2fun main() {3    val (first, second) = swap(4, 9)4    println(first.toString() + ":" + second)5}
    Rust
    1fn swap(a: i32, b: i32) -> (i32, i32) { (b, a) }2fn main() {3    let (first, second) = swap(4, 9);4    println!("{}:{}", first, second);5}
  4. Ownership and Moves

    Kotlin on the JVM uses garbage-collected object references, and assigning a StringBuilder gives another alias without invalidating the first variable. val prevents rebinding but does not stop the demonstrated mutation. Rust owned String follows a different…

    Kotlin
    1fun main() {2    val first = StringBuilder("reed")3    val second = first4    second.setCharAt(0, 's')5    println(first.toString() + ":" + second)6}
    Rust
    1fn main() {2    let first = String::from("reed");3    let mut second = first.clone();4    second.replace_range(0..1, "s");5    let owner = second;6    println!("{}:{}", first, owner);7}
  5. Strings and UTF-8

    Kotlin/JVM String indexes UTF-16 code units, and Char can hold one surrogate rather than a whole supplementary character. The JVM codePointAt operation used here obtains the full first code point. Rust str and String use UTF-8, and chars yields Unicode scalar…

    Kotlin
    1fun main() {2    val text = "𝄞a"3    println(text.codePointAt(0))4}
    Rust
    1fn main() {2    let s = "𝄞a";3    println!("{}", s.chars().next().unwrap() as u32);4}
  6. Option and Matching

    Kotlin nullable types and safe calls make many absence contracts explicit, while ?: chooses a fallback for null. Non-null declarations reduce accidental missing values, although interoperability and unchecked assertions still require care. Rust Option<T> uses…

    Kotlin
    1fun main() {2    val data = arrayOf(6)3    val value = data.getOrNull(2)4    println(value ?: 40)5}
    Rust
    1fn main() {2    let data = [6];3    let value = data.get(2);4    println!("{}", value.copied().unwrap_or(40));5}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Kotlin developers

Learn Rust from another language

Frequently asked questions

Who is Rust for Kotlin Developers for?

For people who already write Kotlin and want to learn Rust. Each lesson starts from Kotlin 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 Kotlin basics: variables, conditions, loops, functions and collections.

How many lessons does Rust for Kotlin Developers have?

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

What does Rust for Kotlin 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 Kotlin 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 Kotlin Developers for free

Get started