permitit 0.1.1

Cute little library to permit a specific error
Documentation
  • Coverage
  • 40%
    2 out of 5 items documented2 out of 5 items with examples
  • Size
  • Source code size: 41.27 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 637.9 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • tox-wtf/permitit
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Toxikuu

Permit it!

Cute little rust library to permit errors

Lets you permit a specific error or permit conditionally for Result<(), E>. Note that this does not work for T. This method may be chained.

Examples

use permitit::Permit;

// Attempt to create a directory, but permit the case where it already exists.
if let Err(e) = std::fs::create_dir("/tmp/dir")
    .permit(|e| e.kind() == std::io::ErrorKind::AlreadyExists)
{
    // If a different error exists, handle it as usual.
    eprintln!("Failed to create /tmp/dir: {e:?}")
}
use permitit::Permit;

// Alternative way to permit the case where a directory already exists.
let path = std::path::PathBuf::from("/tmp/dir");
std::fs::create_dir(&path).permit_if(path.exists()).unwrap_or_else(|e| {
    eprintln!("Failed to create {path:?}: {e:?}")
})

Hint: Look at the tests in src/lib.rs for more usage examples.