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. --- meap/ch1/Cargo.lock | 4 + meap/ch1/Cargo.toml | 7 + meap/ch1/src/main.rs | 28 + meap/ch2/Cargo.lock | 195 + meap/ch2/Cargo.toml | 10 + meap/ch2/src/main.rs | 100 + meap/meap-code/ch1/ch1-animals-specialization.rs | 47 + meap/meap-code/ch1/ch1-animals-tuple-structs.rs | 41 + meap/meap-code/ch1/ch1-animals.rs | 41 + meap/meap-code/ch1/ch1-escape-html.rs | 22 + meap/meap-code/ch1/ch1-hashmap-hashset.rs | 33 + meap/meap-code/ch1/ch1-hello2.rs | 16 + meap/meap-code/ch1/ch1-save-user-data.rs | 32 + meap/meap-code/ch1/ch1-time-api/Cargo.toml | 16 + meap/meap-code/ch1/ch1-time-api/src/main.rs | 36 + meap/meap-code/ch1/ch1-word-counts.rs | 16 + meap/meap-code/ch10/Vagrantfile | 29 + meap/meap-code/ch10/ch10-basic-handler/Cargo.toml | 9 + meap/meap-code/ch10/ch10-basic-handler/Dockerfile | 36 + meap/meap-code/ch10/ch10-basic-handler/Makefile | 2 + meap/meap-code/ch10/ch10-basic-handler/src/main.rs | 58 + meap/meap-code/ch10/ch10-callstack/Cargo.toml | 6 + meap/meap-code/ch10/ch10-callstack/src/main.rs | 21 + meap/meap-code/ch10/ch10-handle/Cargo.toml | 7 + meap/meap-code/ch10/ch10-handle/src/main.rs | 48 + meap/meap-code/ch10/ch10-handler/Cargo.toml | 7 + meap/meap-code/ch10/ch10-handler/src/main.rs | 58 + meap/meap-code/ch10/ch10-ignore/Cargo.toml | 7 + meap/meap-code/ch10/ch10-ignore/src/main.rs | 18 + meap/meap-code/ch10/ch10-sixty/Cargo.toml | 6 + meap/meap-code/ch10/ch10-sixty/src/main.rs | 15 + meap/meap-code/ch10/ch10-sjlj/Cargo.toml | 7 + meap/meap-code/ch10/ch10-sjlj/Dockerfile | 37 + meap/meap-code/ch10/ch10-sjlj/Makefile | 2 + meap/meap-code/ch10/ch10-sjlj/src/main.rs | 105 + meap/meap-code/ch2/ch2-3arrays.rs | 22 + meap/meap-code/ch2/ch2-add-with-lifetimes.rs | 8 + meap/meap-code/ch2/ch2-add-with-lifetimes_.rs | 8 + meap/meap-code/ch2/ch2-bufreader-lines.rs | 13 + meap/meap-code/ch2/ch2-define-type.rs | 22 + meap/meap-code/ch2/ch2-first-steps.rs | 11 + meap/meap-code/ch2/ch2-generic-add.rs | 16 + meap/meap-code/ch2/ch2-intro-to-numbers.rs | 8 + meap/meap-code/ch2/ch2-intro.rs | 18 + meap/meap-code/ch2/ch2-introducing-vec.rs | 52 + meap/meap-code/ch2/ch2-match-needles.rs | 17 + meap/meap-code/ch2/ch2-needle-in-haystack.rs | 15 + meap/meap-code/ch2/ch2-non-base2.rs | 10 + meap/meap-code/ch2/ch2-read-file-iter-lines.rs | 15 + meap/meap-code/ch2/ch2-read-file.rs | 21 + meap/meap-code/ch2/ch2-sensor-emulator.rs | 36 + meap/meap-code/ch2/ch2-simple-with-enumerate.rs | 13 + meap/meap-code/ch2/ch2-simple-with-linenums | Bin 0 -> 3714488 bytes meap/meap-code/ch2/ch2-simple-with-linenums.rs | 14 + meap/meap-code/ch2/ch2-sparse-matrix.rs | 20 + meap/meap-code/ch2/ch2-str-simple-pattern.rs | 12 + meap/meap-code/ch3/ch3-adding-pub-to-file.rs | 28 + meap/meap-code/ch3/ch3-anystring-macro.rs | 10 + meap/meap-code/ch3/ch3-defining-files-neatly.rs | 29 + meap/meap-code/ch3/ch3-defining-files.rs | 18 + meap/meap-code/ch3/ch3-error-1.rs | 30 + meap/meap-code/ch3/ch3-file-doced.rs | 38 + meap/meap-code/ch3/ch3-file-states.rs | 59 + meap/meap-code/ch3/ch3-files-with-modes.rs | 75 + meap/meap-code/ch3/ch3-implementing-display.rs | 49 + meap/meap-code/ch3/ch3-mock-file.rs | 18 + meap/meap-code/ch3/ch3-newtype-pattern.rs | 10 + meap/meap-code/ch3/ch3-not-quite-file-1.rs | 23 + meap/meap-code/ch3/ch3-not-quite-file-2.rs | 42 + meap/meap-code/ch3/ch3-not-quite-file-3.rs | 55 + meap/meap-code/ch3/ch3-not-quite-file-4.rs | 42 + meap/meap-code/ch3/ch3-parse-log.rs | 35 + meap/meap-code/ch3/ch3-public-file.rs | 33 + meap/meap-code/ch3/ch3-return-result.rs | 68 + meap/meap-code/ch3/ch3-skeleton-read-trait.rs | 21 + meap/meap-code/ch3/ch3-string-macro.rs | 10 + meap/meap-code/ch3/filebasics/Cargo.toml | 6 + meap/meap-code/ch3/filebasics/src/main.rs | 3 + meap/meap-code/ch3/fileresult/Cargo.toml | 7 + meap/meap-code/ch3/fileresult/src/main.rs | 65 + meap/meap-code/ch3/globalerror/Cargo.toml | 7 + meap/meap-code/ch3/globalerror/src/main.rs | 30 + meap/meap-code/ch4/ch4-check-sats-1.rs | 27 + meap/meap-code/ch4/ch4-check-sats-3.rs | 33 + .../ch4/ch4-check-sats-clone-and-copy-traits.rs | 24 + .../ch4/ch4-check-sats-with-copy-trait.rs | 46 + meap/meap-code/ch4/ch4-rc-groundstation.rs | 10 + meap/meap-code/ch4/ch4-rc-refcell-groundstation.rs | 31 + meap/meap-code/ch4/ch4-sat-mailbox.rs | 42 + meap/meap-code/ch4/ch4-short-lived-strategy.rs | 82 + meap/meap-code/ch5/ch5-cpu1/Cargo.lock | 4 + meap/meap-code/ch5/ch5-cpu1/Cargo.toml | 6 + meap/meap-code/ch5/ch5-cpu1/src/main.rs | 60 + meap/meap-code/ch5/ch5-cpu2/Cargo.lock | 4 + meap/meap-code/ch5/ch5-cpu2/Cargo.toml | 6 + meap/meap-code/ch5/ch5-cpu2/src/main.rs | 60 + meap/meap-code/ch5/ch5-cpu3/Cargo.lock | 4 + meap/meap-code/ch5/ch5-cpu3/Cargo.toml | 6 + meap/meap-code/ch5/ch5-cpu3/src/main.rs | 88 + meap/meap-code/ch5/ch5-f32-as-u32.rs | 8 + meap/meap-code/ch5/ch5-fixed-width.rs | 34 + meap/meap-code/ch5/ch5-genfib/Cargo.lock | 102 + meap/meap-code/ch5/ch5-genfib/Cargo.toml | 7 + meap/meap-code/ch5/ch5-genfib/src/main.rs | 17 + meap/meap-code/ch5/ch5-impossible-add.rs | 5 + meap/meap-code/ch5/ch5-message-store/Cargo.lock | 4 + meap/meap-code/ch5/ch5-message-store/Cargo.toml | 6 + meap/meap-code/ch5/ch5-message-store/src/main.rs | 93 + meap/meap-code/ch5/ch5-q/Cargo.lock | 127 + meap/meap-code/ch5/ch5-q/Cargo.toml | 7 + meap/meap-code/ch5/ch5-q/src/lib.rs | 76 + .../ch5/ch5-sat-messaging/msg-with-refs/Cargo.lock | 4 + .../ch5/ch5-sat-messaging/msg-with-refs/Cargo.toml | 6 + .../ch5-sat-messaging/msg-with-refs/src/main.rs | 51 + meap/meap-code/ch5/ch5-to-oblivion.rs | 11 + meap/meap-code/ch5/ch5-u8-to-mock-rand.rs | 17 + meap/meap-code/ch5/ch5-visualising-f32.rs | 44 + meap/meap-code/ch6/ch6-gentext/Cargo.lock | 4 + meap/meap-code/ch6/ch6-gentext/Cargo.toml | 6 + meap/meap-code/ch6/ch6-gentext/src/main.rs | 41 + .../ch6/ch6-heap-vs-stack-intro/Cargo.lock | 4 + .../ch6/ch6-heap-vs-stack-intro/Cargo.toml | 6 + .../ch6/ch6-heap-vs-stack-intro/src/main.rs | 6 + meap/meap-code/ch6/ch6-heap-vs-stack/Cargo.lock | 46 + meap/meap-code/ch6/ch6-heap-vs-stack/Cargo.toml | 7 + meap/meap-code/ch6/ch6-heap-vs-stack/src/main.rs | 16 + meap/meap-code/ch6/ch6-meminfo-win/Cargo.lock | 31 + meap/meap-code/ch6/ch6-meminfo-win/Cargo.toml | 9 + meap/meap-code/ch6/ch6-meminfo-win/src/main.rs | 59 + meap/meap-code/ch6/ch6-memscan-1/Cargo.lock | 4 + meap/meap-code/ch6/ch6-memscan-1/Cargo.toml | 6 + meap/meap-code/ch6/ch6-memscan-1/src/main.rs | 14 + meap/meap-code/ch6/ch6-memscan-2/Cargo.lock | 4 + meap/meap-code/ch6/ch6-memscan-2/Cargo.toml | 6 + meap/meap-code/ch6/ch6-memscan-2/src/main.rs | 14 + meap/meap-code/ch6/ch6-memscan-3/Cargo.lock | 4 + meap/meap-code/ch6/ch6-memscan-3/Cargo.toml | 6 + meap/meap-code/ch6/ch6-memscan-3/src/main.rs | 21 + meap/meap-code/ch6/ch6-particles/Cargo.lock | 1239 + meap/meap-code/ch6/ch6-particles/Cargo.toml | 16 + meap/meap-code/ch6/ch6-particles/Dockerfile | 7 + meap/meap-code/ch6/ch6-particles/Vagrantfile | 17 + meap/meap-code/ch6/ch6-particles/src/main.rs | 170 + .../allocation-times-by-allocation-size.png | Bin 0 -> 110328 bytes .../plot-allocation-times-by-allocation-size.plot | 34 + meap/meap-code/ch6/ch6-tracing-output/trace.tsv | 644480 ++++++++++++++++++ meap/meap-code/ch9/Vagrantfile | 29 + meap/meap-code/ch9/ch9-clock0/Cargo.toml | 10 + meap/meap-code/ch9/ch9-clock0/src/main.rs | 8 + meap/meap-code/ch9/ch9-clock1/Cargo.toml | 11 + meap/meap-code/ch9/ch9-clock1/src/main.rs | 53 + meap/meap-code/ch9/ch9-clock2/Cargo.toml | 19 + meap/meap-code/ch9/ch9-clock2/src/main.rs | 132 + meap/meap-code/ch9/ch9-clock3/Cargo.toml | 19 + meap/meap-code/ch9/ch9-clock3/Dockerfile | 10 + meap/meap-code/ch9/ch9-clock3/src/main.rs | 333 + meap/meap-code/ch9/ch9-sao-paulo/Cargo.toml | 8 + meap/meap-code/ch9/ch9-sao-paulo/src/main.rs | 18 + 158 files changed, 650363 insertions(+) create mode 100644 meap/ch1/Cargo.lock create mode 100644 meap/ch1/Cargo.toml create mode 100644 meap/ch1/src/main.rs create mode 100644 meap/ch2/Cargo.lock create mode 100644 meap/ch2/Cargo.toml create mode 100644 meap/ch2/src/main.rs create mode 100644 meap/meap-code/ch1/ch1-animals-specialization.rs create mode 100644 meap/meap-code/ch1/ch1-animals-tuple-structs.rs create mode 100644 meap/meap-code/ch1/ch1-animals.rs create mode 100644 meap/meap-code/ch1/ch1-escape-html.rs create mode 100644 meap/meap-code/ch1/ch1-hashmap-hashset.rs create mode 100644 meap/meap-code/ch1/ch1-hello2.rs create mode 100644 meap/meap-code/ch1/ch1-save-user-data.rs create mode 100644 meap/meap-code/ch1/ch1-time-api/Cargo.toml create mode 100644 meap/meap-code/ch1/ch1-time-api/src/main.rs create mode 100644 meap/meap-code/ch1/ch1-word-counts.rs create mode 100644 meap/meap-code/ch10/Vagrantfile create mode 100644 meap/meap-code/ch10/ch10-basic-handler/Cargo.toml create mode 100644 meap/meap-code/ch10/ch10-basic-handler/Dockerfile create mode 100644 meap/meap-code/ch10/ch10-basic-handler/Makefile create mode 100644 meap/meap-code/ch10/ch10-basic-handler/src/main.rs create mode 100644 meap/meap-code/ch10/ch10-callstack/Cargo.toml create mode 100644 meap/meap-code/ch10/ch10-callstack/src/main.rs create mode 100644 meap/meap-code/ch10/ch10-handle/Cargo.toml create mode 100644 meap/meap-code/ch10/ch10-handle/src/main.rs create mode 100644 meap/meap-code/ch10/ch10-handler/Cargo.toml create mode 100644 meap/meap-code/ch10/ch10-handler/src/main.rs create mode 100644 meap/meap-code/ch10/ch10-ignore/Cargo.toml create mode 100644 meap/meap-code/ch10/ch10-ignore/src/main.rs create mode 100644 meap/meap-code/ch10/ch10-sixty/Cargo.toml create mode 100644 meap/meap-code/ch10/ch10-sixty/src/main.rs create mode 100644 meap/meap-code/ch10/ch10-sjlj/Cargo.toml create mode 100644 meap/meap-code/ch10/ch10-sjlj/Dockerfile create mode 100644 meap/meap-code/ch10/ch10-sjlj/Makefile create mode 100644 meap/meap-code/ch10/ch10-sjlj/src/main.rs create mode 100644 meap/meap-code/ch2/ch2-3arrays.rs create mode 100644 meap/meap-code/ch2/ch2-add-with-lifetimes.rs create mode 100644 meap/meap-code/ch2/ch2-add-with-lifetimes_.rs create mode 100644 meap/meap-code/ch2/ch2-bufreader-lines.rs create mode 100644 meap/meap-code/ch2/ch2-define-type.rs create mode 100644 meap/meap-code/ch2/ch2-first-steps.rs create mode 100644 meap/meap-code/ch2/ch2-generic-add.rs create mode 100644 meap/meap-code/ch2/ch2-intro-to-numbers.rs create mode 100644 meap/meap-code/ch2/ch2-intro.rs create mode 100644 meap/meap-code/ch2/ch2-introducing-vec.rs create mode 100644 meap/meap-code/ch2/ch2-match-needles.rs create mode 100644 meap/meap-code/ch2/ch2-needle-in-haystack.rs create mode 100644 meap/meap-code/ch2/ch2-non-base2.rs create mode 100644 meap/meap-code/ch2/ch2-read-file-iter-lines.rs create mode 100644 meap/meap-code/ch2/ch2-read-file.rs create mode 100644 meap/meap-code/ch2/ch2-sensor-emulator.rs create mode 100644 meap/meap-code/ch2/ch2-simple-with-enumerate.rs create mode 100644 meap/meap-code/ch2/ch2-simple-with-linenums create mode 100644 meap/meap-code/ch2/ch2-simple-with-linenums.rs create mode 100644 meap/meap-code/ch2/ch2-sparse-matrix.rs create mode 100644 meap/meap-code/ch2/ch2-str-simple-pattern.rs create mode 100644 meap/meap-code/ch3/ch3-adding-pub-to-file.rs create mode 100644 meap/meap-code/ch3/ch3-anystring-macro.rs create mode 100644 meap/meap-code/ch3/ch3-defining-files-neatly.rs create mode 100644 meap/meap-code/ch3/ch3-defining-files.rs create mode 100644 meap/meap-code/ch3/ch3-error-1.rs create mode 100644 meap/meap-code/ch3/ch3-file-doced.rs create mode 100644 meap/meap-code/ch3/ch3-file-states.rs create mode 100644 meap/meap-code/ch3/ch3-files-with-modes.rs create mode 100644 meap/meap-code/ch3/ch3-implementing-display.rs create mode 100644 meap/meap-code/ch3/ch3-mock-file.rs create mode 100644 meap/meap-code/ch3/ch3-newtype-pattern.rs create mode 100644 meap/meap-code/ch3/ch3-not-quite-file-1.rs create mode 100644 meap/meap-code/ch3/ch3-not-quite-file-2.rs create mode 100644 meap/meap-code/ch3/ch3-not-quite-file-3.rs create mode 100644 meap/meap-code/ch3/ch3-not-quite-file-4.rs create mode 100644 meap/meap-code/ch3/ch3-parse-log.rs create mode 100644 meap/meap-code/ch3/ch3-public-file.rs create mode 100644 meap/meap-code/ch3/ch3-return-result.rs create mode 100644 meap/meap-code/ch3/ch3-skeleton-read-trait.rs create mode 100644 meap/meap-code/ch3/ch3-string-macro.rs create mode 100644 meap/meap-code/ch3/filebasics/Cargo.toml create mode 100644 meap/meap-code/ch3/filebasics/src/main.rs create mode 100644 meap/meap-code/ch3/fileresult/Cargo.toml create mode 100644 meap/meap-code/ch3/fileresult/src/main.rs create mode 100644 meap/meap-code/ch3/globalerror/Cargo.toml create mode 100644 meap/meap-code/ch3/globalerror/src/main.rs create mode 100644 meap/meap-code/ch4/ch4-check-sats-1.rs create mode 100644 meap/meap-code/ch4/ch4-check-sats-3.rs create mode 100644 meap/meap-code/ch4/ch4-check-sats-clone-and-copy-traits.rs create mode 100644 meap/meap-code/ch4/ch4-check-sats-with-copy-trait.rs create mode 100644 meap/meap-code/ch4/ch4-rc-groundstation.rs create mode 100644 meap/meap-code/ch4/ch4-rc-refcell-groundstation.rs create mode 100644 meap/meap-code/ch4/ch4-sat-mailbox.rs create mode 100644 meap/meap-code/ch4/ch4-short-lived-strategy.rs create mode 100644 meap/meap-code/ch5/ch5-cpu1/Cargo.lock create mode 100644 meap/meap-code/ch5/ch5-cpu1/Cargo.toml create mode 100644 meap/meap-code/ch5/ch5-cpu1/src/main.rs create mode 100644 meap/meap-code/ch5/ch5-cpu2/Cargo.lock create mode 100644 meap/meap-code/ch5/ch5-cpu2/Cargo.toml create mode 100644 meap/meap-code/ch5/ch5-cpu2/src/main.rs create mode 100644 meap/meap-code/ch5/ch5-cpu3/Cargo.lock create mode 100644 meap/meap-code/ch5/ch5-cpu3/Cargo.toml create mode 100644 meap/meap-code/ch5/ch5-cpu3/src/main.rs create mode 100644 meap/meap-code/ch5/ch5-f32-as-u32.rs create mode 100644 meap/meap-code/ch5/ch5-fixed-width.rs create mode 100644 meap/meap-code/ch5/ch5-genfib/Cargo.lock create mode 100644 meap/meap-code/ch5/ch5-genfib/Cargo.toml create mode 100644 meap/meap-code/ch5/ch5-genfib/src/main.rs create mode 100644 meap/meap-code/ch5/ch5-impossible-add.rs create mode 100644 meap/meap-code/ch5/ch5-message-store/Cargo.lock create mode 100644 meap/meap-code/ch5/ch5-message-store/Cargo.toml create mode 100644 meap/meap-code/ch5/ch5-message-store/src/main.rs create mode 100644 meap/meap-code/ch5/ch5-q/Cargo.lock create mode 100644 meap/meap-code/ch5/ch5-q/Cargo.toml create mode 100644 meap/meap-code/ch5/ch5-q/src/lib.rs create mode 100644 meap/meap-code/ch5/ch5-sat-messaging/msg-with-refs/Cargo.lock create mode 100644 meap/meap-code/ch5/ch5-sat-messaging/msg-with-refs/Cargo.toml create mode 100644 meap/meap-code/ch5/ch5-sat-messaging/msg-with-refs/src/main.rs create mode 100644 meap/meap-code/ch5/ch5-to-oblivion.rs create mode 100644 meap/meap-code/ch5/ch5-u8-to-mock-rand.rs create mode 100644 meap/meap-code/ch5/ch5-visualising-f32.rs create mode 100644 meap/meap-code/ch6/ch6-gentext/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-gentext/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-gentext/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-heap-vs-stack-intro/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-heap-vs-stack-intro/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-heap-vs-stack-intro/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-heap-vs-stack/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-heap-vs-stack/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-heap-vs-stack/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-meminfo-win/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-meminfo-win/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-meminfo-win/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-memscan-1/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-memscan-1/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-memscan-1/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-memscan-2/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-memscan-2/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-memscan-2/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-memscan-3/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-memscan-3/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-memscan-3/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-particles/Cargo.lock create mode 100644 meap/meap-code/ch6/ch6-particles/Cargo.toml create mode 100644 meap/meap-code/ch6/ch6-particles/Dockerfile create mode 100644 meap/meap-code/ch6/ch6-particles/Vagrantfile create mode 100644 meap/meap-code/ch6/ch6-particles/src/main.rs create mode 100644 meap/meap-code/ch6/ch6-tracing-output/allocation-times-by-allocation-size.png create mode 100644 meap/meap-code/ch6/ch6-tracing-output/plot-allocation-times-by-allocation-size.plot create mode 100644 meap/meap-code/ch6/ch6-tracing-output/trace.tsv create mode 100644 meap/meap-code/ch9/Vagrantfile create mode 100644 meap/meap-code/ch9/ch9-clock0/Cargo.toml create mode 100644 meap/meap-code/ch9/ch9-clock0/src/main.rs create mode 100644 meap/meap-code/ch9/ch9-clock1/Cargo.toml create mode 100644 meap/meap-code/ch9/ch9-clock1/src/main.rs create mode 100644 meap/meap-code/ch9/ch9-clock2/Cargo.toml create mode 100644 meap/meap-code/ch9/ch9-clock2/src/main.rs create mode 100644 meap/meap-code/ch9/ch9-clock3/Cargo.toml create mode 100644 meap/meap-code/ch9/ch9-clock3/Dockerfile create mode 100644 meap/meap-code/ch9/ch9-clock3/src/main.rs create mode 100644 meap/meap-code/ch9/ch9-sao-paulo/Cargo.toml create mode 100644 meap/meap-code/ch9/ch9-sao-paulo/src/main.rs (limited to 'meap') diff --git a/meap/ch1/Cargo.lock b/meap/ch1/Cargo.lock new file mode 100644 index 0000000..d9d119e --- /dev/null +++ b/meap/ch1/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ch1" +version = "0.1.0" + diff --git a/meap/ch1/Cargo.toml b/meap/ch1/Cargo.toml new file mode 100644 index 0000000..b8034fe --- /dev/null +++ b/meap/ch1/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "ch1" +version = "0.1.0" +authors = ["Adam Carpenter <53hornet@gmail.com>"] +edition = "2018" + +[dependencies] diff --git a/meap/ch1/src/main.rs b/meap/ch1/src/main.rs new file mode 100644 index 0000000..cbeadc4 --- /dev/null +++ b/meap/ch1/src/main.rs @@ -0,0 +1,28 @@ +//use std::rc::Rc; +//use std::sync::{Arc, Mutex}; + +fn main() { +// let a = 10; +// +// if a == 10 { +// println!("a eq ten"); +// } + + +// let a = 10; // stack +// let b = Box::new(10); // heap +// let c = Rc::new(10); // heap, reference count +// let d = Arc::new(Mutex::new(10)); // mutex lock, atomic reference counter +// println!("{} {} {} {:?}", a, b, c, d); + + + let english = "Hello, world!"; + let german = "Grüß Gott!"; + let japanese = "ハロー・ワール"; + let languages = [english, german, japanese]; + + for language in languages.iter() { + println!("{}", language); + } +} + diff --git a/meap/ch2/Cargo.lock b/meap/ch2/Cargo.lock new file mode 100644 index 0000000..4ebdd46 --- /dev/null +++ b/meap/ch2/Cargo.lock @@ -0,0 +1,195 @@ +[[package]] +name = "aho-corasick" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atty" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "ch2" +version = "0.1.0" +dependencies = [ + "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "clap" +version = "2.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lazy_static" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.50" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_syscall" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "strsim" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "termion" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "textwrap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucd-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicode-width" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8-ranges" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "vec_map" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" +"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" +"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" +"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" +"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" +"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" +"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" +"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" +"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" +"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/meap/ch2/Cargo.toml b/meap/ch2/Cargo.toml new file mode 100644 index 0000000..94dc2f4 --- /dev/null +++ b/meap/ch2/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "ch2" +version = "0.1.0" +authors = ["Adam Carpenter <53hornet@gmail.com>"] +edition = "2018" + +[dependencies] +regex = "0.2.2" +clap = "2.24.2" + diff --git a/meap/ch2/src/main.rs b/meap/ch2/src/main.rs new file mode 100644 index 0000000..055ec1c --- /dev/null +++ b/meap/ch2/src/main.rs @@ -0,0 +1,100 @@ +extern crate regex; +extern crate clap; + +use regex::Regex; +use clap::{App, Arg}; +//use std::ops::{Add}; + +fn main() { +// let a = 10; +// let b: i32 = 20; +// +// let c = add(a, b); +// println!("a + b = {}", c); + + +// let twenty = 20; +// let twenty_one: i32 = twenty + 1; +// let floats_okay = 21.0; +// let million = 1_000_000; +// +// println!("{} {} {} {}", twenty, twenty_one, floats_okay, million); +// +// let three = 0b11; +// let thirty = 0o36; +// let three_hundred = 0x12c; +// +// println!("{} {} {}", three, thirty, three_hundred); +// println!("{:b} {:b} {:b}", three, thirty, three_hundred); +// println!("{:o} {:o} {:o}", three, thirty, three_hundred); +// println!("{:x} {:x} {:x}", three, thirty, three_hundred); + + +// //let needle = 42; +// let haystack = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862]; +// +// for reference in haystack.iter() { +// let item = *reference; +// +// //if item == needle { +// // println!("{}", item); +// //} +// +// //if reference == &needle { +// // println!("{}", reference); +// //} +// +// let result = match item { +// 42 | 132 => "hit", +// _ => "miss", +// }; +// +// println!("{}", result); +// } + + + // let (a, b) = (1.2, 3.4); + // let (x, y) = (10, 20); + + // let c = add(a, b); + // let z = add(x, y); + + // println!("{} {}", c, z); + + + let args = App::new("ch2") + .version("0.1") + .about("searches for patterns") + .arg(Arg::with_name("pattern") + .help("the pattern to search for") + .takes_value(true) + .required(true)) + .get_matches(); + + let pattern = args.value_of("pattern").unwrap(); + let re = Regex::new(pattern).unwrap(); + let quote = "Every face, every shop, bedroom window, public-house, \ + and\ndark square is a picture feverishly turned--in search \ + of what?\nIt is the same with books. What do we seek through \ + millions of pages?"; + + for (index, line) in quote.lines().enumerate() { + match re.find(line) { + Some(_) => print!("-> "), + None => print!(" "), + }; + + let line_num = index + 1; + println!("{}: {}", line_num, line); + } + +} + +//fn add>(i: T, j: T) -> T { +// i + j +//} + + +//fn add(i: i32, j: i32) -> i32 { +// i + j +//} diff --git a/meap/meap-code/ch1/ch1-animals-specialization.rs b/meap/meap-code/ch1/ch1-animals-specialization.rs new file mode 100644 index 0000000..49fc0eb --- /dev/null +++ b/meap/meap-code/ch1/ch1-animals-specialization.rs @@ -0,0 +1,47 @@ +struct Animal { + age: i32, +} + +type Cat = Animal; +type Dog = Animal; +type LoudDog = Dog; + +trait Talk { + fn talk(&self) -> (); +} + +impl Talk for Animal { + default fn talk(&self) { // note the use of the default + println!(""); + } +} + +impl Talk for Cat { + fn talk(&self) { + println!("Meow"); + } +} + +impl Talk for Dog { + fn talk(&self) { + println!("Woof!"); + } +} + +impl Talk for LoudDog { + fn talk(&self) { + println!("WOOF!!"); + } +} + + + +fn main() { + let fluffy = Cat(Animal { age: 4 }); + let max = Dog(Animal { age: 2 }); + let neighbours_dog = LoudDog(Animal { age: 7 }); + + fluffy.talk(); + max.talk(); + neighbours_dog.talk(); +} diff --git a/meap/meap-code/ch1/ch1-animals-tuple-structs.rs b/meap/meap-code/ch1/ch1-animals-tuple-structs.rs new file mode 100644 index 0000000..ed479ed --- /dev/null +++ b/meap/meap-code/ch1/ch1-animals-tuple-structs.rs @@ -0,0 +1,41 @@ +struct Animal { + age: i32, +} + +struct Cat(Animal); +struct Dog(Animal); +struct LoudDog(Animal); + +trait Talk { + fn talk(&self) -> (); +} + +impl Talk for Cat { + fn talk(&self) { + println!("Meow"); + } +} + +impl Talk for Dog { + fn talk(&self) { + println!("Woof!"); + } +} + +impl Talk for LoudDog { + fn talk(&self) { + println!("WOOF!!"); + } +} + + + +fn main() { + let fluffy = Cat(Animal { age: 4 }); + let max = Dog(Animal { age: 2 }); + let neighbours_dog = LoudDog(Animal { age: 7 }); + + fluffy.talk(); + max.talk(); + neighbours_dog.talk(); +} diff --git a/meap/meap-code/ch1/ch1-animals.rs b/meap/meap-code/ch1/ch1-animals.rs new file mode 100644 index 0000000..ed479ed --- /dev/null +++ b/meap/meap-code/ch1/ch1-animals.rs @@ -0,0 +1,41 @@ +struct Animal { + age: i32, +} + +struct Cat(Animal); +struct Dog(Animal); +struct LoudDog(Animal); + +trait Talk { + fn talk(&self) -> (); +} + +impl Talk for Cat { + fn talk(&self) { + println!("Meow"); + } +} + +impl Talk for Dog { + fn talk(&self) { + println!("Woof!"); + } +} + +impl Talk for LoudDog { + fn talk(&self) { + println!("WOOF!!"); + } +} + + + +fn main() { + let fluffy = Cat(Animal { age: 4 }); + let max = Dog(Animal { age: 2 }); + let neighbours_dog = LoudDog(Animal { age: 7 }); + + fluffy.talk(); + max.talk(); + neighbours_dog.talk(); +} diff --git a/meap/meap-code/ch1/ch1-escape-html.rs b/meap/meap-code/ch1/ch1-escape-html.rs new file mode 100644 index 0000000..7b61232 --- /dev/null +++ b/meap/meap-code/ch1/ch1-escape-html.rs @@ -0,0 +1,22 @@ +fn escape_html(maybe_html: &str) -> String { + let mut out = String::with_capacity(maybe_html.len()); + + for c in maybe_html.chars() { + match c { + '<' => out.push_str("<"), + '>' => out.push_str(">"), + '&' => out.push_str("&"), + '\'' => out.push_str("'"), + '"' => out.push_str("""), + _ => out.push(c), + }; + } + + out +} + +fn main() { + let html = "

\"Hello, World!\"

"; + let escaped_html = escape_html(html); + println!("{}", escaped_html); +} diff --git a/meap/meap-code/ch1/ch1-hashmap-hashset.rs b/meap/meap-code/ch1/ch1-hashmap-hashset.rs new file mode 100644 index 0000000..1fa9229 --- /dev/null +++ b/meap/meap-code/ch1/ch1-hashmap-hashset.rs @@ -0,0 +1,33 @@ +use std::collections::{HashMap, HashSet}; + +fn main() { + + let input_text = "does this work + i dont know + how rust works"; + + let mut character_counts = HashMap::new(); + + let mut n_lines = 0u32; + + for l in input_text.lines() { + n_lines = n_lines + 1; + + let mut chars_for_line = HashSet::new(); + + for c in l.chars() { + if chars_for_line.contains(&c) { + continue + } + let c_count = character_counts.entry(c).or_insert(0u32); + *c_count += 1; + chars_for_line.insert(c); + } + } + + for (c, c_count) in &character_counts { + if *c_count == n_lines { + println!("{}", c); + } + } +} diff --git a/meap/meap-code/ch1/ch1-hello2.rs b/meap/meap-code/ch1/ch1-hello2.rs new file mode 100644 index 0000000..c804513 --- /dev/null +++ b/meap/meap-code/ch1/ch1-hello2.rs @@ -0,0 +1,16 @@ +fn greet_world() { + println!("Hello, world!"); // our old friend. + + let southern_germany = "Grüß Gott!"; + let japan = "ハロー・ワールド"; + + let regions = [southern_germany, japan]; + + for region in regions.iter() { + println!("{}", ®ion); + } +} + +fn main() { + greet_world(); +} \ No newline at end of file diff --git a/meap/meap-code/ch1/ch1-save-user-data.rs b/meap/meap-code/ch1/ch1-save-user-data.rs new file mode 100644 index 0000000..48f8130 --- /dev/null +++ b/meap/meap-code/ch1/ch1-save-user-data.rs @@ -0,0 +1,32 @@ +use std::str; + +#[derive(Debug)] +struct User { + id: u8, + secret: String, +} + +fn store_secrets(user: &User, buffer: &mut[u8]) { + let _secret = user.secret.clone(); + + + // assume we're writing to a database + println!("{:?}: {}", user, str::from_utf8(&buffer).unwrap()); +} + +fn main() { + let buffer = &mut[0u8; 1024]; + let u1 = User { + id: 1, + secret: String::from("Pa55w0rd!"), + }; + let u2 = User { + id: 2, + secret: String::from("correct horse battery staple"), + }; + + store_secrets(&u1, buffer); + store_secrets(&u2, buffer); + + +} \ No newline at end of file diff --git a/meap/meap-code/ch1/ch1-time-api/Cargo.toml b/meap/meap-code/ch1/ch1-time-api/Cargo.toml new file mode 100644 index 0000000..da28bde --- /dev/null +++ b/meap/meap-code/ch1/ch1-time-api/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ch1-time-api" +version = "0.1.0" +authors = ["Tim McNamara "] + +[dependencies] +chrono = "0.4.0" +rocket = "0.3.0" +rocket_codegen = "0.3.0" +serde = "1.0" +serde_derive = "1.0" + +[dependencies.rocket_contrib] +version = "0.3.0" +default-features = false +features = ["json"] \ No newline at end of file diff --git a/meap/meap-code/ch1/ch1-time-api/src/main.rs b/meap/meap-code/ch1/ch1-time-api/src/main.rs new file mode 100644 index 0000000..660c1cc --- /dev/null +++ b/meap/meap-code/ch1/ch1-time-api/src/main.rs @@ -0,0 +1,36 @@ +#![feature(plugin)] // <1> +#![plugin(rocket_codegen)] // <1> + +extern crate serde; // <2> +extern crate chrono; // <2> +extern crate rocket; // <2> +extern crate rocket_contrib; // <2> + +#[macro_use] // <3> Syntax to indicate that we want to import macros from another module +extern crate serde_derive; // <3> + +use chrono::prelude::*; // <4> brings all exported members into local scope (e.g. DateTime and Utc) +use rocket_contrib::{Json}; // <5> bring single member into local scope + +#[derive(Serialize)] // <6> Automatically generate a string representation of this struct (which will be used as JSON) +struct Timestamp { // <7> Syntax to create a custom type + time: String, // <8> The `Timestamp` `time` field is of type `String` +} + +#[get("/")] // <9> Custom syntax provided by the library that indicates to code generation +fn index() -> &'static str { // <10> Define a function with no arguments and its return type + "Hello, world!" // <11> Rust returns the result of the final expression +} + +#[get("/time")] +fn time_now() -> Json { + let now: DateTime = Utc::now(); + let timestamp = Timestamp { time: now.to_rfc3339() }; + Json(timestamp) +} + +fn main() { + rocket::ignite() + .mount("/", routes![index, time_now]) + .launch(); +} \ No newline at end of file diff --git a/meap/meap-code/ch1/ch1-word-counts.rs b/meap/meap-code/ch1/ch1-word-counts.rs new file mode 100644 index 0000000..fc5c8ea --- /dev/null +++ b/meap/meap-code/ch1/ch1-word-counts.rs @@ -0,0 +1,16 @@ +use std::collections::HashMap; + +fn main() { + let text = "once upon a time ..."; + let mut word_counts = HashMap::new(); + + let pairs = text.split(" ") + .map(|x| { (x, 1) }); + + for (word, count) in pairs { + let tmp = word_counts.entry(word) + .or_insert(0); + *tmp += count; + } + println!("{:?}", word_counts); +} diff --git a/meap/meap-code/ch10/Vagrantfile b/meap/meap-code/ch10/Vagrantfile new file mode 100644 index 0000000..b306dd1 --- /dev/null +++ b/meap/meap-code/ch10/Vagrantfile @@ -0,0 +1,29 @@ +VAGRANTFILE_VERSION = "2" + +$provision_external = <