RBE custom types structs

This commit is contained in:
Dan Buch 2021-09-11 13:42:09 -04:00
parent 798575d9ef
commit 013a8faa2f
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7
2 changed files with 62 additions and 0 deletions

View File

@ -1,4 +1,7 @@
/custom_types/*
/hello/*
/primitives/*
!/custom_types/*.rs
!/hello/*.rs
!/primitives/*.rs

View File

@ -0,0 +1,59 @@
#[derive(Debug)]
struct Person {
name: String,
age: u8,
}
struct Unit;
struct Pair(i32, f32);
struct Point {
x: f32,
y: f32,
}
#[allow(dead_code)]
struct Rectangle {
top_left: Point,
bottom_right: Point,
}
fn main() {
let name = String::from("Peter");
let age = 27;
let peter = Person { name, age };
println!("{:?}", peter);
let point: Point = Point { x: 10.3, y: 0.4 };
println!("point coordinates: ({}, {})", point.x, point.y);
let bottom_right = Point { x: 5.2, ..point };
println!("second point: ({}, {})", bottom_right.x, bottom_right.y);
let Point {
x: left_edge,
y: top_edge,
} = point;
let _rectangle = Rectangle {
top_left: Point {
x: left_edge,
y: top_edge,
},
bottom_right: bottom_right,
};
let _unit = Unit;
let pair = Pair(1, 0.1);
println!("pair contains {:?} and {:?}", pair.0, pair.1);
let Pair(integer, decimal) = pair;
println!("pair contains {:?} and {:?}", integer, decimal);
}