IfEmpty
A crate to use for defensive programming where context specific defaults are needed.
Motivation
While using an Option is preferrably in most circumstances there are situations where a function call
doesn't return a Option and the Default of a type isn't helpful either.
You now have the option to wrap this special function call or write something along these lines:
let foo = ;
Using this crate you can reduce this down to:
let foo = bar.if_empty;
Implementing this for your own type
In order to take advantage of this feature you have to implement this behavior for your types:
use *;
See derive_macro for how to use the #[derive] macro.
Provided types
The crate provides this functionality for String, OsString, &str and &OsStr.