permitit

Crates.iopermitit
lib.rspermitit
version0.1.1
created_at2025-04-21 21:28:06.542487+00
updated_at2025-05-04 20:22:44.907562+00
descriptionCute little library to permit a specific error
homepage
repositoryhttps://github.com/Toxikuu/permit.git
max_upload_size
id1643224
size41,738
Toxikuu (Toxikuu)

documentation

README

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.

Commit count: 0

cargo fmt