Skip to content

Commit

Permalink
change http headers callback FnMut<> to Fn<>
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLocal committed Sep 5, 2024
1 parent a5a0a86 commit f4b911a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ fn start_zlm_background(

let uri = format!("http://127.0.0.1:{}{}", AXUM_PORT, path_query);
let headers = msg.parser.headers();

println!("uri: {}", uri);
println!("headers: {:?}", headers);
if let Ok(mut req) = hyper::Request::builder()
.method(msg.parser.method().as_str())
.uri(uri)
Expand Down
12 changes: 7 additions & 5 deletions src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ impl Parser {
pub fn headers(&self) -> HashMap<String, String> {
let headers = std::rc::Rc::new(RefCell::new(HashMap::new()));

let headers_clone = headers.clone();
self.headers_for_each(Box::new(move |key, val| {
headers_clone.borrow_mut().insert(key, val);
self.headers_for_each(Box::new({
let headers_clone = headers.clone();
move |key, val| {
headers_clone.borrow_mut().insert(key, val);
}
}));

let tmp = headers.as_ref().borrow().to_owned();
Expand All @@ -331,14 +333,14 @@ impl Parser {
}
}

type ParserHeadersForEachCallbackFn = Box<dyn FnMut(String, String) + 'static>;
type ParserHeadersForEachCallbackFn = Box<dyn Fn(String, String) + 'static>;
extern "C" fn parser_headers_for_each(
user_data: *mut ::std::os::raw::c_void,
key: *const ::std::os::raw::c_char,
val: *const ::std::os::raw::c_char,
) {
unsafe {
let cb: &mut ParserHeadersForEachCallbackFn = std::mem::transmute(user_data);
let cb: &ParserHeadersForEachCallbackFn = std::mem::transmute(user_data);
let key = const_ptr_to_string!(key);
let val = const_ptr_to_string!(val);
cb(key, val);
Expand Down

0 comments on commit f4b911a

Please sign in to comment.