Crate fmtor

Source
Expand description

§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))
);

Structs§

MaybeFormat
The type returned from FmtOr::fmt_or_empty
MaybeFormatOr
The type returned from FmtOr::fmt_or
MaybeFormatOrElse
The type returned from FmtOr::fmt_or_else

Traits§

FmtOr
An extension trait for Option<T>. The methods on this trait are the inteded way to use this crate.