mirror of
https://github.com/ArthurDanjou/rustlings.git
synced 2026-02-04 05:37:50 +01:00
- Created empty solution files for various exercises in strings, modules, hashmaps, options, error handling, generics, traits, lifetimes, tests, iterators, smart pointers, threads, macros, clippy, conversions, and quizzes. - Each solution file contains a main function with a comment indicating that it will be automatically filled after completing the exercise. - Added a README.md file to provide information about the solutions and their purpose.
21 lines
483 B
Rust
21 lines
483 B
Rust
// Don't change this function.
|
|
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
|
if x.len() > y.len() {
|
|
x
|
|
} else {
|
|
y
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
// TODO: Fix the compiler error by moving one line.
|
|
|
|
let string1 = String::from("long string is long");
|
|
let result;
|
|
let string2 = String::from("xyz");
|
|
{
|
|
result = longest(&string1, &string2);
|
|
}
|
|
println!("The longest string is '{result}'"); // This line should be removed or moved
|
|
}
|