From 9a23a0ce9b0c29f55476b0b5db7160db645e77b2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 8 Feb 2019 14:40:38 -0500 Subject: [PATCH] Add advanced_types example --- .idea/misc.xml | 1 + .idea/rust.iml | 5 ++ .idea/workspace.xml | 129 +++++++++++++++---------------------- advanced_types/Cargo.toml | 7 ++ advanced_types/src/main.rs | 16 +++++ 5 files changed, 80 insertions(+), 78 deletions(-) create mode 100644 advanced_types/Cargo.toml create mode 100644 advanced_types/src/main.rs diff --git a/.idea/misc.xml b/.idea/misc.xml index 66727c9..06e172b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -39,6 +39,7 @@ + diff --git a/.idea/rust.iml b/.idea/rust.iml index 0831f61..54d35f8 100644 --- a/.idea/rust.iml +++ b/.idea/rust.iml @@ -157,11 +157,16 @@ + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b841b27..5708fa1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -13,39 +13,16 @@ - + - + - - - - - - - - - - - - - - - - - - - - + + - - - - - @@ -75,7 +52,6 @@ @@ -135,11 +112,11 @@ false false - + @@ -149,28 +126,6 @@ - - - - - - - - - - - - - - - - - - - - + + - + @@ -226,7 +203,7 @@ - + - + @@ -304,11 +281,11 @@ + - @@ -348,8 +325,8 @@ - - + + @@ -357,7 +334,7 @@ - + @@ -379,13 +356,6 @@ - - - - - - - @@ -634,9 +604,7 @@ - - - + @@ -807,13 +775,11 @@ - - - + - - + + @@ -835,5 +801,12 @@ + + + + + + + \ No newline at end of file diff --git a/advanced_types/Cargo.toml b/advanced_types/Cargo.toml new file mode 100644 index 0000000..d2a1ff9 --- /dev/null +++ b/advanced_types/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "advanced_types" +version = "0.1.0" +authors = ["Timothy Warren "] +edition = "2018" + +[dependencies] diff --git a/advanced_types/src/main.rs b/advanced_types/src/main.rs new file mode 100644 index 0000000..3dcc829 --- /dev/null +++ b/advanced_types/src/main.rs @@ -0,0 +1,16 @@ +// Type alias, just gives a new name to the existing type. +// Considered the same type, even using the new name +type Kilometers = i32; + +// A type alias is much more useful for a long, complex type +type Thunk = Box; + +fn main() { + let x: i32 = 5; + let y: Kilometers = 5; + + println!("x + y = {}", x + y); + + let f: Thunk = Box::new(|| println!("hi")); + f(); +}