unwrap-log

Crates.iounwrap-log
lib.rsunwrap-log
version0.1.1
sourcesrc
created_at2023-08-06 21:19:33.440191
updated_at2023-08-06 22:33:23.595918
descriptionNon-panicking alternatives to `Option` and `Result` unwrapping, which log at warn level
homepagehttps://github.com/ryanavella/unwrap-log-rs
repositoryhttps://github.com/ryanavella/unwrap-log-rs
max_upload_size
id937409
size10,811
Ryan Avella (ryanavella)

documentation

https://docs.rs/unwrap-log

README

unwrap-log

Non-panicking alternatives to Option and Result unwrapping, which log at warn level.

License: MIT License: Unlicense crates.io docs.rs

Example

use unwrap_log::{OptionExt, ResultExt};
use env_logger::Builder;
use log::LevelFilter::Warn;

Builder::new().filter_level(Warn).init();

let x: i32 = None.unwrap_or_default_log();
assert_eq!(x, 0);

let y: i32 = Err("oops").unwrap_or_default_log();
assert_eq!(y, 0);

Output:

[1970-01-01T00:00:00Z WARN  my_crate] src\main.rs:8:23 encountered `None`
[1970-01-01T00:00:00Z WARN  my_crate] src\main.rs:11:30 encountered `Err("oops")`
Commit count: 2

cargo fmt