#macro

if-let-return

Simple macro for if let ... pattern

1 unstable release

0.1.0 Sep 12, 2018

#162 in #macro

Download history 2/week @ 2018-10-04 18/week @ 2018-10-11 13/week @ 2018-10-18 2/week @ 2018-10-25 10/week @ 2018-11-01 6/week @ 2018-11-08 1/week @ 2018-11-15 3/week @ 2018-11-22 8/week @ 2018-11-29 6/week @ 2018-12-06 2/week @ 2018-12-13 9/week @ 2018-12-20 3/week @ 2018-12-27 1/week @ 2019-01-03 4/week @ 2019-01-10

3 downloads per month

Custom license

7KB

if-let-return

Simple macros for if let ....

Usage

if_let_some!

pub fn read(&self, wrapped_data: Option<&str>) -> Vec<u8> {
  let data = if let Some(data) = wrapped_data {
    data
  } else {
    return vec![];
  }

  some_function(data);

  ...
}

pub fn read(&self, wrapped_data: Option<&str>) -> Vec<u8> {
  if_let_some!(data = wrapped_data, vec![]);

  some_function(data);

  ...
}

if_let_ok!

pub fn read(&self, wrapped_data: Result<&str, Error>) -> Vec<u8> {
  let data = match wrapped_data {
    Ok(data) => data,
    Err(err) => return err.to_vec(),
  };

  some_function(data);
  ...
}

pub fn read(&self, wrapped_data: Result<&str, Error>) -> Vec<u8> {
  if_let_ok!(data = wrapped_data, |err| err.to_vec());

  some_function(data);
  ...
}

No runtime deps