Why isn't there a `std::fs::read()` function?
⚓ Rust 📅 2025-12-07 👤 surdeus 👁️ 1Currently in Rust's std there are 2 functions that read directly the content of a file:
fn read<P: AsRef<Path>>(path: P) -> Result<Vec<u8>>
and
fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String>
the question that I ask myself is, why isn't there a trait (e.g. FromRead / Readable, ...) that could allow to do this:
fn read<P: AsRef<Path>, T: FromRead>(path: P) -> Result<T>
Was that ever thought when designing std::fs ? If so, what are the arguments against it ?
1 post - 1 participant
🏷️ Rust_feed