4 Commits

Author SHA1 Message Date
Kivanc Gunalp
4e9b5735ad Use more idiomatic Rust in file_io2/file_io3
- file_io2: replace the manual line_number counter with
  .lines().enumerate(), and replace
  buffered_file_writer.write(format!(...).as_bytes()) with writeln!,
  which both formats and guarantees a complete write (write_fmt loops
  internally, unlike a single Write::write call).
- file_io3: replace the manual match on file_path.parent() with
  .ok_or_else(...)? for a more idiomatic Option-to-Result conversion.

Verified locally: both solutions compile under edition 2024, clippy is
silent, and running them still produces identical output (3 lines
processed / 117-byte file, non-readonly permissions) with no leftover
files.
2026-07-26 15:48:35 +00:00
Kivanc Gunalp
e0859583b3 Fix clippy collapsible_if in file_io3 cleanup
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.
2026-07-26 15:34:10 +00:00
Kivanc Gunalp
68f8369cb4 Harden file_io exercises: remove magic number, dedupe paths
- 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.
2026-07-26 15:27:53 +00:00
Kivanc Gunalp
316311e08c Add file I/O exercises (file_io1-3)
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.
2026-07-26 15:09:01 +00:00