From 5718a0b54869b341bc74416bf82b716aa15d582c Mon Sep 17 00:00:00 2001 From: Adam Carpenter <53hornet@gmail.com> Date: Tue, 26 Mar 2019 15:05:10 -0400 Subject: Finished web server project. Book done! --- advanced/adv-fn-closure/Cargo.lock | 7 ++++ advanced/adv-fn-closure/Cargo.toml | 1 + advanced/adv-fn-closure/src/main.rs | 82 +++++++++++++++++++++++++++++++++---- advanced/hello_macro/Cargo.toml | 7 ++++ advanced/hello_macro/src/lib.rs | 3 ++ 5 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 advanced/hello_macro/Cargo.toml create mode 100644 advanced/hello_macro/src/lib.rs (limited to 'advanced') diff --git a/advanced/adv-fn-closure/Cargo.lock b/advanced/adv-fn-closure/Cargo.lock index cfa8ec5..360607c 100644 --- a/advanced/adv-fn-closure/Cargo.lock +++ b/advanced/adv-fn-closure/Cargo.lock @@ -1,4 +1,11 @@ [[package]] name = "adv-fn-closure" version = "0.1.0" +dependencies = [ + "hello_macro 0.1.0", +] + +[[package]] +name = "hello_macro" +version = "0.1.0" diff --git a/advanced/adv-fn-closure/Cargo.toml b/advanced/adv-fn-closure/Cargo.toml index 259562e..6cd8dbd 100644 --- a/advanced/adv-fn-closure/Cargo.toml +++ b/advanced/adv-fn-closure/Cargo.toml @@ -5,3 +5,4 @@ authors = ["Adam Carpenter <53hornet@gmail.com>"] edition = "2018" [dependencies] +hello_macro = { path = "../hello_macro" } diff --git a/advanced/adv-fn-closure/src/main.rs b/advanced/adv-fn-closure/src/main.rs index d31bd90..064f300 100644 --- a/advanced/adv-fn-closure/src/main.rs +++ b/advanced/adv-fn-closure/src/main.rs @@ -1,13 +1,79 @@ -fn add_one(x: i32) -> i32 { - x + 1 -} +use hello_macro::HelloMacro; +//use hello_macro_derive::HelloMacro; + +struct Pancakes; -fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { - f(arg) + f(arg) +impl HelloMacro for Pancakes { + fn hello_macro() { + println!("pancakes"); + } } fn main() { - let answer = do_twice(add_one, 5); - - println!("{}", answer); + Pancakes::hello_macro(); } + +//fn add_one(x: i32) -> i32 { +// x + 1 +//} +// +//fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { +// f(arg) + f(arg) +//} + + +//fn returns_closure() -> Box i32> { +// Box::new(|x| x + 1) +//} +// +// +//enum Status { +// Value(u32), +// Stop, +//} + + +//#[macro_export] +//macro_rules! vec { +// ( $( $x:expr ), * ) => { +// { +// let mut temp_vec = Vec::new(); +// $( +// temp_vec.push($x); +// )* +// temp_vec +// } +// }; +//} + + +//#[some_attribute] +//pub fn some_name(input: TokenStream) -> TokenStream { +//} +// +// +//fn main() { +// let answer = do_twice(add_one, 5); +// +// println!("{}", answer); + + +// let list_of_numbers = vec![1, 2, 3]; +// let list_of_strings: Vec = list_of_numbers +// .iter() +// .map(ToString::to_string) +// .collect(); +// dbg!(list_of_strings); + + +// let list_of_statuses: Vec = +// (0u32..20) +// .map(Status::Value) +// .collect(); + + + //returns_closure(); + + + +//} diff --git a/advanced/hello_macro/Cargo.toml b/advanced/hello_macro/Cargo.toml new file mode 100644 index 0000000..e812230 --- /dev/null +++ b/advanced/hello_macro/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "hello_macro" +version = "0.1.0" +authors = ["Adam Carpenter <53hornet@gmail.com>"] +edition = "2018" + +[dependencies] diff --git a/advanced/hello_macro/src/lib.rs b/advanced/hello_macro/src/lib.rs new file mode 100644 index 0000000..e747931 --- /dev/null +++ b/advanced/hello_macro/src/lib.rs @@ -0,0 +1,3 @@ +pub trait HelloMacro { + fn hello_macro(); +} -- cgit v1.2.3