io-extra 0.3.0

An extension trait for `std::io::Error`, with shorthand constructors for various `std::io::ErrorKind`s.
Documentation
  • Coverage
  • 100%
    25 out of 25 items documented3 out of 24 items with examples
  • Size
  • Source code size: 8.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.7 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • aatifsyed/io-extra
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • aatifsyed

An extension trait for [io::Error], with shorthand constructors for various [io::ErrorKind]s, and a [context()] method.

use std::{fs::File, io::{self, Write as _}, str};
use io_extra::{IoErrorExt as _, context, with};

fn write_log(contents: &[u8], mut file: File) -> io::Result<()> {
    if let Err(e) = str::from_utf8(contents) {
        return Err(io::Error::invalid_input("`contents` was not UTF-8"))
                           // ^ shorthand constructor
    }
    file.write_all(contents).map_err(with("couldn't write file"))
                                  // ^ easily add context
}