Skip to content

Instantly share code, notes, and snippets.

@werner
Created July 26, 2017 13:46
Show Gist options
  • Save werner/4ed5aff5d88c621d2249d63f4850a509 to your computer and use it in GitHub Desktop.
Save werner/4ed5aff5d88c621d2249d63f4850a509 to your computer and use it in GitHub Desktop.
Macro borrowing problem
macro_rules! get_body_as {
($structure:ty, $req:expr, $error_fn:ident) => {
{
let body = get_body!($req, $error_fn);
let raw_structure = borrow_function(&body);
match raw_structure {
Ok(structure) => structure,
Err(error) => "Error"
}
}
}
}
macro_rules! get_body {
($req:expr, $error_fn:ident) => {
{
let mut payload = String::new();
payload
}
}
}
fn borrow_function(s: &str) -> Result<&str, &str> {
Ok(s)
}
fn main() {
let function1 = |s: &str| s;
let body = get_body_as!(&str, "Hello", function1);
println!("Hello");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment