diff options
54 files changed, 101 insertions, 29 deletions
diff --git a/lifetimes/Cargo.lock b/lifetimes/Cargo.lock new file mode 100644 index 0000000..0c2507e --- /dev/null +++ b/lifetimes/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "lifetimes" +version = "0.1.0" + diff --git a/lifetimes/Cargo.toml b/lifetimes/Cargo.toml new file mode 100644 index 0000000..8003864 --- /dev/null +++ b/lifetimes/Cargo.toml @@ -0,0 +1,7 @@ +[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 new file mode 100644 index 0000000..87b6ce6 --- /dev/null +++ b/lifetimes/src/main.rs @@ -0,0 +1,43 @@ +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); +} diff --git a/lifetimes/target/.rustc_info.json b/lifetimes/target/.rustc_info.json new file mode 100644 index 0000000..63426f8 --- /dev/null +++ b/lifetimes/target/.rustc_info.json @@ -0,0 +1 @@ +{"rustc_fingerprint":13848232676847739476,"outputs":{"15337506775154344876":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/adam/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""],"1617349019360157463":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/adam/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""],"1164083562126845933":["rustc 1.32.0 (9fda7c223 2019-01-16)\nbinary: rustc\ncommit-hash: 9fda7c2237db910e41d6a712e9a2139b352e558b\ncommit-date: 2019-01-16\nhost: x86_64-unknown-linux-gnu\nrelease: 1.32.0\nLLVM version: 8.0\n",""]},"successes":{}}
\ No newline at end of file diff --git a/lifetimes/target/debug/.cargo-lock b/lifetimes/target/debug/.cargo-lock new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lifetimes/target/debug/.cargo-lock diff --git a/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/bin-lifetimes-efb5637f417930c3 b/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/bin-lifetimes-efb5637f417930c3 new file mode 100644 index 0000000..f146f56 --- /dev/null +++ b/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/bin-lifetimes-efb5637f417930c3 @@ -0,0 +1 @@ +c7df6e6b96a818a1
\ No newline at end of file diff --git a/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/bin-lifetimes-efb5637f417930c3.json b/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/bin-lifetimes-efb5637f417930c3.json new file mode 100644 index 0000000..3f090d3 --- /dev/null +++ b/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/bin-lifetimes-efb5637f417930c3.json @@ -0,0 +1 @@ +{"rustc":11779505878581416876,"features":"[]","target":17218091323931530620,"profile":1241200217276728497,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1550322003,293604958],".fingerprint/lifetimes-efb5637f417930c3/dep-bin-lifetimes-efb5637f417930c3"]}],"rustflags":[],"edition":"Edition2018"}
\ No newline at end of file diff --git a/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/dep-bin-lifetimes-efb5637f417930c3 b/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/dep-bin-lifetimes-efb5637f417930c3 Binary files differnew file mode 100644 index 0000000..e046c38 --- /dev/null +++ b/lifetimes/target/debug/.fingerprint/lifetimes-efb5637f417930c3/dep-bin-lifetimes-efb5637f417930c3 diff --git a/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3 b/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3 Binary files differnew file mode 100755 index 0000000..8edfb67 --- /dev/null +++ b/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3 diff --git a/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3.d b/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3.d new file mode 100644 index 0000000..0a866ec --- /dev/null +++ b/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3.d @@ -0,0 +1,5 @@ +/home/adam/devel/learning-rust/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3: src/main.rs + +/home/adam/devel/learning-rust/lifetimes/target/debug/deps/lifetimes-efb5637f417930c3.d: src/main.rs + +src/main.rs: diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/10oafshzgt3w3xeo.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/10oafshzgt3w3xeo.o Binary files differnew file mode 100644 index 0000000..46d47f0 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/10oafshzgt3w3xeo.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/12ep0b6r7gf5xev8.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/12ep0b6r7gf5xev8.o Binary files differnew file mode 100644 index 0000000..a010637 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/12ep0b6r7gf5xev8.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/15o4oy1d5i2cot5y.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/15o4oy1d5i2cot5y.o Binary files differnew file mode 100644 index 0000000..e4908a1 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/15o4oy1d5i2cot5y.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1dqcrqv4ajxjkaig.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1dqcrqv4ajxjkaig.o Binary files differnew file mode 100644 index 0000000..4e616c8 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1dqcrqv4ajxjkaig.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1dswbkuzj3w28w51.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1dswbkuzj3w28w51.o Binary files differnew file mode 100644 index 0000000..4fa58cd --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1dswbkuzj3w28w51.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1gqqj20irkfzwcwh.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1gqqj20irkfzwcwh.o Binary files differnew file mode 100644 index 0000000..30eb5b5 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1gqqj20irkfzwcwh.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1imy25kgsjnvggrs.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1imy25kgsjnvggrs.o Binary files differnew file mode 100644 index 0000000..32d6655 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1imy25kgsjnvggrs.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1ji0leyxj7ek98ow.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1ji0leyxj7ek98ow.o Binary files differnew file mode 100644 index 0000000..9c2dda3 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1ji0leyxj7ek98ow.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1mrdfm11mjvkc3ae.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1mrdfm11mjvkc3ae.o Binary files differnew file mode 100644 index 0000000..e972532 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1mrdfm11mjvkc3ae.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1nf5yxicd99au96g.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1nf5yxicd99au96g.o Binary files differnew file mode 100644 index 0000000..1b534ed --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1nf5yxicd99au96g.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1s7p0acfczq7s1kq.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1s7p0acfczq7s1kq.o Binary files differnew file mode 100644 index 0000000..27a89ac --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1s7p0acfczq7s1kq.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1umnfcvuqn4ilt61.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1umnfcvuqn4ilt61.o Binary files differnew file mode 100644 index 0000000..b22c7fa --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1umnfcvuqn4ilt61.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1wcconq124fi8jmy.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1wcconq124fi8jmy.o Binary files differnew file mode 100644 index 0000000..62acf8c --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/1wcconq124fi8jmy.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/20cjgxwra8j8ma5.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/20cjgxwra8j8ma5.o Binary files differnew file mode 100644 index 0000000..a6e8da1 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/20cjgxwra8j8ma5.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/2eb6dzxk4fpfgct2.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/2eb6dzxk4fpfgct2.o Binary files differnew file mode 100644 index 0000000..b9a374f --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/2eb6dzxk4fpfgct2.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/2kn7sctw717hdvxv.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/2kn7sctw717hdvxv.o Binary files differnew file mode 100644 index 0000000..8fb1747 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/2kn7sctw717hdvxv.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/36p29dusvnnao4l6.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/36p29dusvnnao4l6.o Binary files differnew file mode 100644 index 0000000..e32ab85 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/36p29dusvnnao4l6.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/37lsqijwyl9hcqdy.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/37lsqijwyl9hcqdy.o Binary files differnew file mode 100644 index 0000000..76c27d4 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/37lsqijwyl9hcqdy.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3mtnm9o8g1d4ay08.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3mtnm9o8g1d4ay08.o Binary files differnew file mode 100644 index 0000000..33c6a67 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3mtnm9o8g1d4ay08.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3o7odmue6rclr07q.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3o7odmue6rclr07q.o Binary files differnew file mode 100644 index 0000000..c96f742 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3o7odmue6rclr07q.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3ovm9mpazp54gvkw.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3ovm9mpazp54gvkw.o Binary files differnew file mode 100644 index 0000000..a72caa9 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3ovm9mpazp54gvkw.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3vrsmjefktbf358o.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3vrsmjefktbf358o.o Binary files differnew file mode 100644 index 0000000..ae25150 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3vrsmjefktbf358o.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3x4s2wz09up1dm2n.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3x4s2wz09up1dm2n.o Binary files differnew file mode 100644 index 0000000..e4e926b --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3x4s2wz09up1dm2n.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3znqya38t8dwe2at.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3znqya38t8dwe2at.o Binary files differnew file mode 100644 index 0000000..a159fc1 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/3znqya38t8dwe2at.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/45ny6671yk2ypgvo.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/45ny6671yk2ypgvo.o Binary files differnew file mode 100644 index 0000000..668efd9 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/45ny6671yk2ypgvo.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4git0qmjrupi8t61.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4git0qmjrupi8t61.o Binary files differnew file mode 100644 index 0000000..585cee6 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4git0qmjrupi8t61.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4glxfcni5mbpugli.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4glxfcni5mbpugli.o Binary files differnew file mode 100644 index 0000000..4f591ee --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4glxfcni5mbpugli.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4inaqhg23zqxyqnc.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4inaqhg23zqxyqnc.o Binary files differnew file mode 100644 index 0000000..f1af3d3 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4inaqhg23zqxyqnc.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4m39n3seakb54iax.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4m39n3seakb54iax.o Binary files differnew file mode 100644 index 0000000..7244487 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4m39n3seakb54iax.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4z4nzjl4q0pz1f04.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4z4nzjl4q0pz1f04.o Binary files differnew file mode 100644 index 0000000..4171c9b --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/4z4nzjl4q0pz1f04.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/50eev5qtb13tzx9b.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/50eev5qtb13tzx9b.o Binary files differnew file mode 100644 index 0000000..9886ab0 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/50eev5qtb13tzx9b.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/51gmswjzv1agzg8f.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/51gmswjzv1agzg8f.o Binary files differnew file mode 100644 index 0000000..8603195 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/51gmswjzv1agzg8f.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/5d28jwqkfvzyq5h1.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/5d28jwqkfvzyq5h1.o Binary files differnew file mode 100644 index 0000000..886b43c --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/5d28jwqkfvzyq5h1.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/b9nyaare4e7lyek.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/b9nyaare4e7lyek.o Binary files differnew file mode 100644 index 0000000..0081563 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/b9nyaare4e7lyek.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/dep-graph.bin b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/dep-graph.bin Binary files differnew file mode 100644 index 0000000..7761f62 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/dep-graph.bin diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/pqtu3yin1ijq83m.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/pqtu3yin1ijq83m.o Binary files differnew file mode 100644 index 0000000..1ec80cd --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/pqtu3yin1ijq83m.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/query-cache.bin b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/query-cache.bin Binary files differnew file mode 100644 index 0000000..4a19fa1 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/query-cache.bin diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/tq446ynsxari1o4.o b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/tq446ynsxari1o4.o Binary files differnew file mode 100644 index 0000000..3bc6782 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/tq446ynsxari1o4.o diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/work-products.bin b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/work-products.bin Binary files differnew file mode 100644 index 0000000..00826d6 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8-20lj7ul63d9hr/work-products.bin diff --git a/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8.lock b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8.lock new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/lifetimes/target/debug/incremental/lifetimes-2xzusyx2j7lm/s-f9jk3gevx7-13gs7v8.lock diff --git a/lifetimes/target/debug/lifetimes b/lifetimes/target/debug/lifetimes Binary files differnew file mode 100755 index 0000000..8edfb67 --- /dev/null +++ b/lifetimes/target/debug/lifetimes diff --git a/lifetimes/target/debug/lifetimes.d b/lifetimes/target/debug/lifetimes.d new file mode 100644 index 0000000..deabab0 --- /dev/null +++ b/lifetimes/target/debug/lifetimes.d @@ -0,0 +1 @@ +/home/adam/devel/learning-rust/lifetimes/target/debug/lifetimes: /home/adam/devel/learning-rust/lifetimes/src/main.rs diff --git a/minigrep/src/lib.rs b/minigrep/src/lib.rs new file mode 100644 index 0000000..78610ba --- /dev/null +++ b/minigrep/src/lib.rs @@ -0,0 +1,29 @@ +use std::error::Error; +use std::fs; + +pub struct Config { + pub query: String, + pub filename: String, +} + +impl Config { + + pub fn new(args: &[String]) -> Result<Config, &'static str> { + + if args.len() < 3 { + return Err("Not enough arguments."); + } + + let query = args[1].clone(); + let filename = args[2].clone(); + Ok(Config { query, filename }) + } + +} + +pub fn run(config: Config) -> Result<(), Box<dyn Error>> { + let contents = fs::read_to_string(config.filename)?; + dbg!(contents); + Ok(()) +} + diff --git a/minigrep/src/main.rs b/minigrep/src/main.rs index 1e04b5e..fc5ae9a 100644 --- a/minigrep/src/main.rs +++ b/minigrep/src/main.rs @@ -1,6 +1,8 @@ use std::process; use std::env; -use std::fs; + +use minigrep; +use minigrep::Config; fn main() { let args: Vec<String> = env::args().collect(); @@ -8,33 +10,11 @@ fn main() { println!("Problem parsing arguments: {}", err); process::exit(1); }); - - println!("Searching for {}", config.query); - println!("In file {}", config.filename); - - let contents = fs::read_to_string(config.filename) - .expect("something went wrong."); - - dbg!(contents); -} - -struct Config { - query: String, - filename: String, -} - -impl Config { - - - fn new(args: &[String]) -> Result<Config, &'static str> { - - if args.len() < 3 { - panic!("not enough args"); - } - - let query = args[1].clone(); - let filename = args[2].clone(); - Ok(Config { query, filename }) + println!("\nSearching for {}", config.query); + println!(" in file {}", config.filename); + if let Err(e) = minigrep::run(config) { + println!("Application error: {}", e); + process::exit(1); } - } + |