dev-check runs clippy with -D warnings against the solutions, which
flagged the nested if let Some(dir_path) = ... { if dir_path.exists() ... }
in file_cleanup as collapsible. Combined into a single if-let with a
let-chain condition (edition = "2024", so this is available).
Verified locally: compiles under --edition 2024, clippy is silent,
and the binary still runs cleanly with file size 117 and no leftover
files.
- file_io3: replace the hardcoded expected file size (117) with
SAMPLE_TEXT.len(), so the check is derived from the actual content
instead of an unexplained magic number.
- file_io3: use create_dir_all instead of create_dir, and add a
sample_file_path() helper shared by main/create_required_files/
file_cleanup to avoid three separate ad-hoc path constructions.
- file_io1/file_io2: hoist the sample text into a SAMPLE_TEXT constant
used by both the exercise and its solution, removing duplicated
literals.
No behavioral change: all three solutions were rebuilt and run
locally, producing identical output (file size still 117, permissions
still non-readonly) with no leftover files.
Adds file_io1-3 (and their solutions) to dev/Cargo.toml's bin list so
'cargo dev check'/'cargo dev update' pick them up, and registers them in
rustlings-macros/info.toml with hints that explain each exercise's
learning goal and point at the relevant std API.
Adds three new exercises under exercises/24_file_io/, as proposed in rust-lang/rustlings#2233:
- file_io1: read a whole file with fs::read_to_string and handle the Result.
- file_io2: read/write a file efficiently with BufReader/BufWriter.
- file_io3: build a path with PathBuf and inspect it with .metadata().
Includes matching solutions and a README describing the learning goal of
each exercise.
To understand From-based conversion, an understanding of traits is
required, which we teach in a later chapter. The From trait specifically
is taught in one of the conversion exercises. So, we can safely remove
it here without users missing out on learning something important.
A specific source of confusion for users was a warning that the
conversion is useless, which appeared when using the `string_slice`
function for the expression with `.into()`. closes#2190
Conversion between Celsius and Fahrenheit should be understandable to
most. Inverting the formula is still not very hard, but a little harder
than only multiplying by 100.
Learners were sometimes confused by the literal array. Their assumption
was that they are supposed to convert the array to a vector. Duplicating
the literal elements was not an intuitive solution.
This redesign avoids putting an identical array literal near the place
where learners are supposed to use the vec! macro.
This was discussed in another PR, but it was merged before the code was
updated to the most recent consensus:
https://github.com/rust-lang/rustlings/pull/2353
Co-authored-by: Piotr Spieker <p.spieker@posteo.de>
This avoids confusion between `.into_iter()` and `.iter()`. On a slice,
both methods do the same (correct) thing. Using `.into_iter()` will
result in a clippy warning about the slice not being consumed.