From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ch12-an-io-project/listing-12-07/Cargo.lock | 6 ++++ .../ch12-an-io-project/listing-12-07/Cargo.toml | 6 ++++ .../ch12-an-io-project/listing-12-07/output.txt | 6 ++++ .../ch12-an-io-project/listing-12-07/poem.txt | 9 +++++ .../ch12-an-io-project/listing-12-07/src/main.rs | 40 ++++++++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.lock create mode 100644 src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.toml create mode 100644 src/doc/book/listings/ch12-an-io-project/listing-12-07/output.txt create mode 100644 src/doc/book/listings/ch12-an-io-project/listing-12-07/poem.txt create mode 100644 src/doc/book/listings/ch12-an-io-project/listing-12-07/src/main.rs (limited to 'src/doc/book/listings/ch12-an-io-project/listing-12-07') diff --git a/src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.lock b/src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.lock new file mode 100644 index 000000000..88bf82d16 --- /dev/null +++ b/src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "minigrep" +version = "0.1.0" + diff --git a/src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.toml b/src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.toml new file mode 100644 index 000000000..64c2a3f52 --- /dev/null +++ b/src/doc/book/listings/ch12-an-io-project/listing-12-07/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "minigrep" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/src/doc/book/listings/ch12-an-io-project/listing-12-07/output.txt b/src/doc/book/listings/ch12-an-io-project/listing-12-07/output.txt new file mode 100644 index 000000000..d3fa7777d --- /dev/null +++ b/src/doc/book/listings/ch12-an-io-project/listing-12-07/output.txt @@ -0,0 +1,6 @@ +$ cargo run + Compiling minigrep v0.1.0 (file:///projects/minigrep) + Finished dev [unoptimized + debuginfo] target(s) in 0.0s + Running `target/debug/minigrep` +thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:27:21 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/src/doc/book/listings/ch12-an-io-project/listing-12-07/poem.txt b/src/doc/book/listings/ch12-an-io-project/listing-12-07/poem.txt new file mode 100644 index 000000000..870752731 --- /dev/null +++ b/src/doc/book/listings/ch12-an-io-project/listing-12-07/poem.txt @@ -0,0 +1,9 @@ +I'm nobody! Who are you? +Are you nobody, too? +Then there's a pair of us - don't tell! +They'd banish us, you know. + +How dreary to be somebody! +How public, like a frog +To tell your name the livelong day +To an admiring bog! diff --git a/src/doc/book/listings/ch12-an-io-project/listing-12-07/src/main.rs b/src/doc/book/listings/ch12-an-io-project/listing-12-07/src/main.rs new file mode 100644 index 000000000..ff6c29420 --- /dev/null +++ b/src/doc/book/listings/ch12-an-io-project/listing-12-07/src/main.rs @@ -0,0 +1,40 @@ +use std::env; +use std::fs; + +// ANCHOR: here +fn main() { + let args: Vec = env::args().collect(); + + let config = Config::new(&args); + // ANCHOR_END: here + + println!("Searching for {}", config.query); + println!("In file {}", config.file_path); + + let contents = fs::read_to_string(config.file_path) + .expect("Should have been able to read the file"); + + println!("With text:\n{contents}"); + // ANCHOR: here + + // --snip-- +} + +// --snip-- + +// ANCHOR_END: here +struct Config { + query: String, + file_path: String, +} + +// ANCHOR: here +impl Config { + fn new(args: &[String]) -> Config { + let query = args[1].clone(); + let file_path = args[2].clone(); + + Config { query, file_path } + } +} +// ANCHOR_END: here -- cgit v1.2.3