mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-08-14 22:36:57 +00:00
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 IO
Rust provides several file I/O functions in the standard library. Buffered reads and writes provide better performance by reducing the number of underlying system calls.
Learning goals
- file_io1 — Read an entire file into memory with
fs::read_to_stringand handle theResultit returns instead of unwrapping blindly, so you get comfortable with the basic "open, read, handle the error" pattern that most file I/O in Rust builds on. - file_io2 — Wrap a
Filein aBufReaderto read it line by line and aBufWriterto write the transformed output, so you understand why buffering matters for I/O performance and howBufRead::lineslets you process input incrementally instead of loading it all at once. - file_io3 — Build a path with
PathBuf, then call.metadata()to inspect properties like creation time, size, and permissions, so you can work with the filesystem safely across platforms without hardcoding path separators.
Further information
Here is the documentation for these functions in the standard library.