https://github.com/jaemk/wrap
Rust wrapping macro
https://github.com/jaemk/wrap
function-wrapper rust rustlang wrap wrapper
Last synced: about 1 month ago
JSON representation
Rust wrapping macro
- Host: GitHub
- URL: https://github.com/jaemk/wrap
- Owner: jaemk
- License: mit
- Created: 2017-04-06T02:04:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-09T19:29:06.000Z (about 8 years ago)
- Last Synced: 2025-03-28T02:48:36.908Z (about 2 months ago)
- Topics: function-wrapper, rust, rustlang, wrap, wrapper
- Language: Rust
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wrap [](https://travis-ci.org/jaemk/wrap) [](https://crates.io/crates/wrap) [](https://docs.rs/wrap)
> generalized rust wrapping macro
Macros for defining generalized `wrappers` and applying them to arbitrary functions. See `examples` for more advanced `wrappers`.
## Simple Usage
```rust,ignore
#[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"));
}
```