trpl-zh-cn/listings/ch20-advanced-features/listing-20-15/src/lib.rs

13 lines
237 B
Rust
Raw Normal View History

2022-02-06 16:43:51 +08:00
use std::ops::Add;
struct Millimeters(u32);
struct Meters(u32);
impl Add<Meters> for Millimeters {
type Output = Millimeters;
fn add(self, other: Meters) -> Millimeters {
Millimeters(self.0 + (other.0 * 1000))
}
}