Hi
How can I access everything inside this function inside a main function when this function is called inside the main?
fn on_message() -> Callbacks<'a, T> {
let mut mc = m.callbacks(());
mc.on_message(|_,msg| {
if ! msg.retained() {
if bonzo.matches(&msg) {
println!("bonzo {:?}",msg);
} else
if frodo.matches(&msg) {
println!("frodo {:?}",msg);
}
}
mc
});
}
Link to the mqtt client library I use: GitHub - stevedonovan/mosquitto-client
Thanks
skysch
March 4, 2020, 10:49pm
2
Who is going to access what? The main function can't do anything while a function it calls is on the stack, and you can access anything you like with a debugger. So your question doesn't make much sense as is.
Inside main this function is called and main will have access to everything inside this function.
skysch
March 4, 2020, 11:27pm
5
What is "everything"? The only thing inside that function is a Callbacks<'a, T>
, which isn't in that function once it is returned, so what exactly do you want to do?
I want the callback to be executed once the function is called in main.
ExpHP
March 5, 2020, 1:08am
8
Write it as a closure inside main:
fn main() {
let on_message = || -> Callbacks<'a, T> {
let mut mc = m.callbacks(());
mc.on_message(|_,msg| {
if ! msg.retained() {
if bonzo.matches(&msg) {
println!("bonzo {:?}",msg);
} else
if frodo.matches(&msg) {
println!("frodo {:?}",msg);
}
}
mc
});
}
Does that mean I no longer need to call the on_message function in main?
system
Closed
June 3, 2020, 1:29am
10
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.