unwrap_goto

Crates.iounwrap_goto
lib.rsunwrap_goto
version0.1.2
sourcesrc
created_at2022-07-29 10:32:03.532499
updated_at2022-08-09 03:32:28.738762
descriptionunwrap Option an Result or goto `return`/`cotinue`/`break` as you want.
homepagehttps://github.com/mu2019/unwrap_goto
repositoryhttps://github.com/mu2019/unwrap_goto
max_upload_size
id634932
size9,297
(mu2019)

documentation

README

unwrap_goto

unwrap Option an Result data. When data is wrap with Some or Ok, it will unwrap, otherwise can goto return/cotinue/break as you want.

When none will return.

#[macro_use]
extern crate unwrap_goto;
fn do_none_is_return(m: &Vec<Option<i32>>) {
    let mut k = 0;
    for v in m {
        println!("imcome:{:?}", v);
        k = some_or_return!(v);
        println!("wrap value:{:?}", k);
    }
    assert_eq!(k, 1);
    0
}

fn none_is_return() {
    let m = vec![Some(1), None, Some(1)];
    let n = do_none_is_return(&m);
    println!("return value:{:?}", n);
} 

fn do_none_is_return(m: &Vec<Option<i32>>) -> i64 {
    let mut k = 0;
    for v in m {
        println!("imcome:{:?}", v);
        k = some_or_return!(v, 8);
        println!("wrap value:{:?}", k);
    }
    assert_eq!(k, 1);
    0
}

fn none_is_return() {
    let m = vec![Some(1), None, Some(1)];
    let n = do_none_is_return(&m);
    println!("return value:{:?}", n);
} 

use log::error;

fn call_when_err_return_log() {
    let x: Result<i32, &str> = Err("Some error message");
    ok_or_return!(x, (), error!("log error info.{:?}", x));
    println!("anything print out");
}
Commit count: 7

cargo fmt