2 个不稳定版本

使用旧的 Rust 2015

0.1.0 2017年4月7日
0.0.1 2017年4月5日

#2968Rust 模式

Download history 18/week @ 2024-03-13 30/week @ 2024-03-20 36/week @ 2024-03-27 151/week @ 2024-04-03 174/week @ 2024-04-10 170/week @ 2024-04-17 21/week @ 2024-04-24 12/week @ 2024-05-01 4/week @ 2024-05-08 19/week @ 2024-05-15 105/week @ 2024-05-22 96/week @ 2024-05-29 33/week @ 2024-06-05 44/week @ 2024-06-12 13/week @ 2024-06-19 11/week @ 2024-06-26

每月105 次下载

MIT 许可证

7KB
61

wrap

通用 Rust 包装宏

定义通用 包装器 的宏,并将它们应用于任意函数。请参阅 examples

简单用法

#[macro_use] extern crate wrap;


def_wrapper!{log1 =
    before = (fn_args) >> {
        println!("* [log-1] >> before everything! fn_args: {:?}", fn_args);
    };
    after  = (wrapped_result) >> {
        println!("* [log-1] >> after everything! wrapped_result: {:?}", wrapped_result);
    };
}


def_wrapper!{log2 =
    before = (fn_args) >> {
        println!("* [log-2] >> before everything! fn_args: {:?}", fn_args);
    };
    after  = (wrapped_result) >> {
        println!("* [log-2] >> after everything! wrapped_result: {:?}", wrapped_result);
    };
}


wrap_with!{log1 >>
fn greet_logged_inner(name: &str) -> String = {
    format!("How are you, {}?", name)
}}


wrap_with!{log2 >>
fn greet_logged(name: &str) -> String = {
    format!("Hello! {}", greet_logged_inner(name))
}}


pub fn main() {
    println!("{}", greet_logged("james"));
}

无运行时依赖