Trait Example – Rust Code Typing Test
Implements a trait for a struct to define common behavior.
- 18 lines
- 228 chars
- ≈ 1m 08s at 40 WPM
Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
trait Greet {
fn greet(&self);
}
struct Person {
name: String,
}
impl Greet for Person {
fn greet(&self) {
println!("Hello, {}!", self.name);
}
}
fn main() {
let person = Person { name: String::from("Alice") };
person.greet();
}Coding works best on desktop or with an external keyboard.