Document error macros

This commit is contained in:
Julian Ospald 2017-07-15 01:54:22 +02:00
parent c57622fad5
commit 7542d8beaf
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 8 additions and 0 deletions

View File

@ -21,6 +21,8 @@ error_chain! {
#[macro_export]
/// Try to unwrap a `Result<T, E>`. If there is a value `T`, yield it,
/// otherwise print a warning and `return ()` from the function.
macro_rules! try_w {
($expr:expr) => {
try_wr!($expr, ())
@ -35,6 +37,8 @@ macro_rules! try_w {
#[macro_export]
/// Try to unwrap a `Result<T, E>`. If there is a value `T`, yield it,
/// otherwise print a warning and return from the function with the given value.
macro_rules! try_wr {
($expr:expr, $ret:expr) => (match $expr {
::std::result::Result::Ok(val) => val,
@ -63,6 +67,8 @@ macro_rules! try_wr {
#[macro_export]
/// Try to unwrap a `Result<T, E>`. If there is a value `T`, yield it,
/// otherwise return from the function with the given value.
macro_rules! try_r {
($expr:expr, $ret:expr) => (match $expr {
::std::result::Result::Ok(val) => val,
@ -75,6 +81,8 @@ macro_rules! try_r {
#[macro_export]
/// Try to unwrap a `Result<T, E>`. If there is a value `T`, yield it,
/// otherwise print an error and exit the program.
macro_rules! try_e {
($expr:expr) => {
try_er!($expr, ())