Interactive coding challenges that teach Rust through hands-on practice — from ownership puzzles to borrow-checker quests.
Start Your QuestFollow the path from beginner to advanced. Each quest builds on the last.
Tackle real Rust problems with instant feedback from the compiler.
fn longest<'a>( x: &'a str, y: &'a str, ) -> &'a str { if x.len() > y.len() { x } else { y } } fn main() { let string1 = String::from("long string"); let result; { let string2 = String::from("xyz"); result = longest( string1.as_str(), string2.as_str(), ); } // Does this compile? Why or why not? println!("{}", result); }
The function longest returns a reference, but the compiler needs to know how long that reference is valid. Analyze this code and determine whether it will compile.
string2 does not live long enough
string2 is dropped while still borrowed by result.
Collect badges as you conquer each quest.