From 67cdcc2e12118becb823e20a40cc2687f2b8425a Mon Sep 17 00:00:00 2001 From: Adam Carpenter <53hornet@gmail.com> Date: Wed, 27 Mar 2019 15:32:37 -0400 Subject: Started Rust in Action MEAP. --- lifetimes/Cargo.lock | 4 ---- lifetimes/Cargo.toml | 7 ------- lifetimes/src/main.rs | 43 ------------------------------------------- 3 files changed, 54 deletions(-) delete mode 100644 lifetimes/Cargo.lock delete mode 100644 lifetimes/Cargo.toml delete mode 100644 lifetimes/src/main.rs (limited to 'lifetimes') diff --git a/lifetimes/Cargo.lock b/lifetimes/Cargo.lock deleted file mode 100644 index 0c2507e..0000000 --- a/lifetimes/Cargo.lock +++ /dev/null @@ -1,4 +0,0 @@ -[[package]] -name = "lifetimes" -version = "0.1.0" - diff --git a/lifetimes/Cargo.toml b/lifetimes/Cargo.toml deleted file mode 100644 index 8003864..0000000 --- a/lifetimes/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "lifetimes" -version = "0.1.0" -authors = ["53hornet <53hornet@gmail.com>"] -edition = "2018" - -[dependencies] diff --git a/lifetimes/src/main.rs b/lifetimes/src/main.rs deleted file mode 100644 index 87b6ce6..0000000 --- a/lifetimes/src/main.rs +++ /dev/null @@ -1,43 +0,0 @@ -fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { - // what this is doing is basically tagging x and y and the - // result with the same 'a, telling rust not to let any - // of them expire before the others; that way nothing - // will go out of scope prematurely and the result will - // always have a non-null reference - - // basically, 'a gives all three values the same lifetime. - // so long as they're all alive at the same time, there are - // no reference errors - - // note that the lifetime selected for the result is - // equal to the smaller of the lifetimes of the - // parameters - - if x.len() > y.len() { - x - } - else { - y - } -} - -struct ImportantExcerpt<'a> { - part: &'a str, -} - -fn main() { - let string1 = String::from("abcd"); - { - let string2 = "xyz"; - - let result = longest(string1.as_str(), string2); - //dbg!(result); - } - - let script = String::from("Before time began, there was the cube. We know not where it comes from."); - let first_sentence = script.split('.') - .next() - .expect("Could not find a '.'"); - let i = ImportantExcerpt { part: first_sentence }; - dbg!(i.part); -} -- cgit v1.2.3