Is the above approach correct? or there is a better way?
I tried to implement a trait so that the function is invoked as f1.invoke() but could not know how to make it, is there a way to make it?
The argument f1: fn() can only accept regular functions or closures with no captured values. If you allow generic f1: impl FnOnce(), then you can also accept closures with captured state.
let user = get_username();
third_fn(
x,
|| println!("Hello, {}", user),
|| println!("Goodbye, {}", user),
);