diff --git a/src/views/select_view.rs b/src/views/select_view.rs index d3a24ee..024faaf 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -1,6 +1,7 @@ use std::cmp::min; use std::rc::Rc; use std::cell::Cell; +use std::borrow::Borrow; use Cursive; use With; @@ -132,7 +133,6 @@ impl SelectView { /// Sets a callback to be used when an item is selected. /// - /// /// Chainable variant. pub fn on_select(self, cb: F) -> Self where F: Fn(&mut Cursive, &T) + 'static @@ -143,10 +143,13 @@ impl SelectView { /// Sets a callback to be used when `` is pressed. /// /// The item currently selected will be given to the callback. - pub fn set_on_submit(&mut self, cb: F) - where F: Fn(&mut Cursive, &T) + 'static + /// + /// Here, `V` can be `T` itself, or a type that can be borrowed from `T`. + pub fn set_on_submit(&mut self, cb: F) + where F: Fn(&mut Cursive, &V) + 'static, + T: Borrow { - self.on_submit = Some(Rc::new(cb)); + self.on_submit = Some(Rc::new(move |s, t| cb(s, t.borrow()))); } /// Sets a callback to be used when `` is pressed. @@ -154,8 +157,9 @@ impl SelectView { /// The item currently selected will be given to the callback. /// /// Chainable variant. - pub fn on_submit(self, cb: F) -> Self - where F: Fn(&mut Cursive, &T) + 'static + pub fn on_submit(self, cb: F) -> Self + where F: Fn(&mut Cursive, &V) + 'static, + T: Borrow { self.with(|s| s.set_on_submit(cb)) }