Given the simple Cursive structure that displays to buttons vertically (one "Choose" that calls choose_model and a quit button) how do I arrange for the function choose_model to be passed some extra information?
let buttons = LinearLayout::vertical()
.child(Button::new("Choose",choose_model))
.child(DummyView)
.child(Button::new("Quit", Cursive::quit));
I would like the function to be passed a directory path in can look in Something like...
let buttons = LinearLayout::vertical()
.child(Button::new("Choose", choose_model, "/tmp")) // Ever hopeful
.child(DummyView)
.child(Button::new("Quit", Cursive::quit));
fn choose_models( s: &mut Cursive, dir:&str){
// Read diretcory dir and get models
// Display models in a widget
// Use a callback to run models
}
Seems to me that there should be a simple solution using a closure, but I cannot find it.
Are you referring to the 'static requirement on the closure? If so, if you can clone your model (or pieces needed for the callback), then you can move those into the closure. Putting that state inside an Rc would make those clones cheap.