3 releases

0.1.2 Nov 5, 2020
0.1.1 Nov 2, 2020
0.1.0 Nov 2, 2020

#70 in #combinator

MIT/Apache

14KB
211 lines

FmtOr

Tests docs.rs MIT Licensed Apache2 Licensed

An extension trait for easily formatting missing values.

Example

use fmtor::FmtOr;

let maybe_box: Option<Box<()>> = None;

println!("The box is at: {:p}", maybe_box.fmt_or("Null"));

Prints: The box is at: Null


lib.rs:

fmtor

See the FmtOr trait.

Examples

use fmtor::FmtOr;

let maybe_ref: Option<&()> = None;

assert_eq!(
    "Null",
    format!("{:p}", maybe_ref.fmt_or("Null"))
);
use fmtor::FmtOr;

struct NullMarker;
impl std::fmt::Display for NullMarker {
    fn fmt(&self, out: &mut std::fmt::Formatter) -> std::fmt::Result {
        out.write_str("Null")
    }    
}
let maybe_ref: Option<&u32> = None;

assert_eq!(
    "Null",
    format!("{:x}", maybe_ref.fmt_or(NullMarker))
);

No runtime deps