Tuple Structs Example
use std::ops::Add; #[derive(Debug)] struct Rectangle(u32, u32); #[derive(Debug)] struct Meters(u32); impl Add for Meters { type Output = u32; fn add(self, arg: Self) -> Self::Output { self.0 * arg.0 } } fn main() { // Basic usage let rect = Rectangle(4, 8); println!("{:?}", rect); println!("Area is {:?}", area(rect)); // Type safety let x = Meters(2); let y = Meters(3); let lenght = x + y; println!("length is {:?}", lenght); } fn area(rect: Rectangle) -> u32 { rect.0 * rect.1 }