Ex 3.1
This commit is contained in:
parent
60689fd103
commit
e7e2d2749c
4
rustbyexample/031/Cargo.lock
generated
Normal file
4
rustbyexample/031/Cargo.lock
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[root]
|
||||||
|
name = "031"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
6
rustbyexample/031/Cargo.toml
Normal file
6
rustbyexample/031/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "031"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Dan Buch <daniel.buch@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
37
rustbyexample/031/src/main.rs
Normal file
37
rustbyexample/031/src/main.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
struct Nil;
|
||||||
|
|
||||||
|
struct Pair(i32, f32);
|
||||||
|
|
||||||
|
struct Point {
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
struct Rectangle {
|
||||||
|
p1: Point,
|
||||||
|
p2: Point,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let point: Point = Point { x: 0.3, y: 0.4 };
|
||||||
|
|
||||||
|
println!("point coordinates: ({}, {})", point.x, point.y);
|
||||||
|
|
||||||
|
let Point { x: my_x, y: my_y } = point;
|
||||||
|
|
||||||
|
let _rectangle = Rectangle {
|
||||||
|
p1: Point { x: my_y, y: my_x },
|
||||||
|
p2: point,
|
||||||
|
};
|
||||||
|
|
||||||
|
let _nil = Nil;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user