From e7e2d2749c9c3a30ed25d3ea4fe86f1ed0ce1423 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 5 Sep 2016 22:41:08 -0400 Subject: [PATCH] Ex 3.1 --- rustbyexample/031/Cargo.lock | 4 ++++ rustbyexample/031/Cargo.toml | 6 ++++++ rustbyexample/031/src/main.rs | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 rustbyexample/031/Cargo.lock create mode 100644 rustbyexample/031/Cargo.toml create mode 100644 rustbyexample/031/src/main.rs diff --git a/rustbyexample/031/Cargo.lock b/rustbyexample/031/Cargo.lock new file mode 100644 index 0000000..a720929 --- /dev/null +++ b/rustbyexample/031/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "031" +version = "0.1.0" + diff --git a/rustbyexample/031/Cargo.toml b/rustbyexample/031/Cargo.toml new file mode 100644 index 0000000..13d08f7 --- /dev/null +++ b/rustbyexample/031/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "031" +version = "0.1.0" +authors = ["Dan Buch "] + +[dependencies] diff --git a/rustbyexample/031/src/main.rs b/rustbyexample/031/src/main.rs new file mode 100644 index 0000000..4515204 --- /dev/null +++ b/rustbyexample/031/src/main.rs @@ -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); +}