Created
July 26, 2017 13:46
-
-
Save werner/4ed5aff5d88c621d2249d63f4850a509 to your computer and use it in GitHub Desktop.
Macro borrowing problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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