2 unstable releases

Uses old Rust 2015

0.1.0 Apr 7, 2017
0.0.1 Apr 5, 2017

#25 in #wrapping

Download history 54/week @ 2024-07-21 39/week @ 2024-07-28 30/week @ 2024-08-04 13/week @ 2024-08-11 8/week @ 2024-08-18 54/week @ 2024-08-25 15/week @ 2024-09-01 53/week @ 2024-09-08 21/week @ 2024-09-15 168/week @ 2024-09-22 82/week @ 2024-09-29 23/week @ 2024-10-06 14/week @ 2024-10-13 3/week @ 2024-10-20 13/week @ 2024-10-27 50/week @ 2024-11-03

81 downloads per month

MIT license

7KB
61 lines

wrap

generalized rust wrapping macro

Macros for defining generalized wrappers and applying them to arbitrary functions. See examples.

Simple Usage

#[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"));
}

No runtime deps