12345678910111213141516171819202122232425 |
- use point::Point;
- fn main() {
- // Default is used to obtain a Point to (0, 0)
- let p: Point<i32> = Point::default();
- // ^
- // Type is assigned here
- println!("p = {}", p); // (0, 0)
- let _p: Point<i32> = Point::<i32>::default();
- // ^
- // Type can be assigned here too
- // Giving just 1 number will assign both x and y
- let p1: Point<u16> = Point::from(3);
- println!("p1 = {}", p1); // (3, 3)
- // Giving a tuple of 2 numbers will assign x and y respectively
- let p2: Point<i64> = Point::from((9_i64, 81));
- // ^ ^
- // x y
- // x also adds the type hint that 9 is an i64 (Which defines the Point to i64)
- // y MUST be i64 also, no mix matching types
- println!("p2 = {}", p2);
- }
|