Exercise solutions
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- rust
- Domain
- cli, documentation
Research direction
Start by reviewing the reader exercises in the book, including the Chapter 1.3 implementation draft linked in the issue and its BufReader example. Determine which exercises need reference solutions and how they should be presented. Done means the requested exercise solutions are available for readers to consult.
Written by the indexing model from the issue text.
Description
Hi, this is a great tutorial!
As I am working through the book, I am trying the reader exercises — it would be great to have some solutions to refer to.
For example, Chapter 1.3 suggests one use a BufReader, so I have an attempt:
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Read;
use clap::Parser;
#[derive(Parser)]
struct Cli {
pattern: String,
#[clap(parse(from_os_str))]
path: std::path::PathBuf,
}
fn main() {
let args: Cli = Cli::parse();
println!(
"You parsed pattern = {:?}, path = {:?}",
&args.pattern, &args.path
);
let f = File::open(&args.path).expect("could not read file");
let mut f = BufReader::new(f);
for line in f.by_ref().lines() {
if line.as_ref().unwrap().contains(&args.pattern) {
println!("{}", line.as_ref().unwrap());
}
}
}
Now I'd like to see how to improve this.
Have I merely missed this somewhere in the book?
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 122
- Avg merge
- 10h 37m
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-cli/book
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Broken Discord link Open
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
bug
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
issue
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
agentic-workflows
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
web-infra-dev/rspack#15847 ·