summaryrefslogtreecommitdiff
path: root/advanced/adv-fn-closure
diff options
context:
space:
mode:
authorAdam Carpenter <53hornet@gmail.com>2019-03-22 16:48:03 -0400
committerAdam Carpenter <53hornet@gmail.com>2019-03-22 16:48:03 -0400
commitcbfe2f1de7f0e24525e641228fec4c659badde93 (patch)
tree5939189ff3e3178e4f740a6038c6ccea7a182c0d /advanced/adv-fn-closure
parentb1ea85616e4367713afbeabb6cfb6ae553c17a60 (diff)
downloadlearning-rust-cbfe2f1de7f0e24525e641228fec4c659badde93.tar.xz
learning-rust-cbfe2f1de7f0e24525e641228fec4c659badde93.zip
Added advanced traits, types, functions.
Diffstat (limited to 'advanced/adv-fn-closure')
-rw-r--r--advanced/adv-fn-closure/Cargo.toml7
-rw-r--r--advanced/adv-fn-closure/src/main.rs13
2 files changed, 20 insertions, 0 deletions
diff --git a/advanced/adv-fn-closure/Cargo.toml b/advanced/adv-fn-closure/Cargo.toml
new file mode 100644
index 0000000..259562e
--- /dev/null
+++ b/advanced/adv-fn-closure/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "adv-fn-closure"
+version = "0.1.0"
+authors = ["Adam Carpenter <53hornet@gmail.com>"]
+edition = "2018"
+
+[dependencies]
diff --git a/advanced/adv-fn-closure/src/main.rs b/advanced/adv-fn-closure/src/main.rs
new file mode 100644
index 0000000..d31bd90
--- /dev/null
+++ b/advanced/adv-fn-closure/src/main.rs
@@ -0,0 +1,13 @@
+fn add_one(x: i32) -> i32 {
+ x + 1
+}
+
+fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
+ f(arg) + f(arg)
+}
+
+fn main() {
+ let answer = do_twice(add_one, 5);
+
+ println!("{}", answer);
+}