/// Like [Result::unwrap] but gives [Err] to a [ProblemReceiver](super::ProblemReceiver) and
/// returns [Ok] if that error is swallowed.
///
/// In practice it can be used somewhat similarly to the `?` operator.
///
/// The first argument is the [Result] and the second is the
/// [ProblemReceiver](super::ProblemReceiver). The optional third argument is the value to return
/// for [Ok] if an [Err] is swallowed by the receiver (it will default to [Default::default].)
///
/// Note that it *must* be implemented as a macro because it includes a `return` statement.
#[macro_export]
macro_rules! give_unwrap {
    ( $result:expr, $receiver:expr $(,)? ) => {
        $crate::give_unwrap!($result, $receiver, ::std::default::Default::default())
    };

    ( $result:expr, $receiver:expr, $ok:expr $(,)? ) => {
        match $result {
            ::std::result::Result::Ok(ok) => ok,
            ::std::result::Result::Err(error) => {
                $crate::ProblemReceiver::give($receiver, error.into())?;
                return ::std::result::Result::Ok($ok);
            }
        }
    };
}

#[allow(unused_imports)]
pub use give_unwrap;
