How I can use the on_message function in scope inside the main function?

Please use the edit post feature instead of posting a new topic.

You can give on_message a borrow of the m variable like this:

fn on_message(m: &mut mosq::Mosquitto) {
    ...
}
fn main() {
    ...
    on_message(&mut m);
    ...
}