Struct with impl in Rust
A struct and its impl block, where Rust puts the methods.
struct Point {
x: f64,
y: f64,
}
impl Point {
fn distance_to(&self, other: &Point) -> f64 {
let dx = self.x - other.x;
let dy = self.y - other.y;
(dx * dx + dy * dy).sqrt()
}
}
Keywords and builtins used here
Pointdistance_tof64fnimplletselfstruct
The run, in numbers
- Lines
- 12
- Characters to type
- 177
- Tokens
- 66
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 42 seconds.
Step 2 of 2 in Structs & methods, step 12 of 15 in Ownership & borrowing.