i have the following function
pub fn start(
self: Arc<Self>,
addr: &str,
control_fn: fn(String) -> bool,
) -> std::io::Result<()>
which does
if !control_fn(tkn.to_owned()) {
let _ = sock.write(b"invalid token\r\n");
continue;
}
in another thread.
when I try to call it in the app
let (_state, app_state) = crate::init::init_cache(streamer.clone());
fn check_tkn(token: String) -> bool {
let uid_token: Vec<&str> = token.split("__").collect();
if uid_token.len() != 2 {
false
} else {
check_token(uid_token[0], uid_token[1], app_state).is_ok()
}
}
streamer
.clone()
.start(&streamer_addr, check_tkn)
.expect("cannot start streamer");
I get all sorts of errors. All I want is simply to check the given token and return bool I cant use closures because apparently closures are not Send I also cannot use function pointers because they cannot use the environment around I also cannot use factory function to capture environment because again the inner function cannot be sent between threads or cannot capture the outer functions environment.
all I want is
fn do_something(...,check(String)->bool){
...
if ! check(data){
return
}
}