diff --git a/src/view/mod.rs b/src/view/mod.rs index d9a1c99..e804a2f 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -66,7 +66,7 @@ use vec::Vec2; use views::IdView; /// Main trait defining a view behaviour. -pub trait View { +pub trait View: Any { /// Called when a key was pressed. /// /// Default implementation just ignores it. diff --git a/src/view/view_wrapper.rs b/src/view/view_wrapper.rs index dcaa3fc..0426e5b 100644 --- a/src/view/view_wrapper.rs +++ b/src/view/view_wrapper.rs @@ -14,7 +14,7 @@ use view::{Selector, View}; /// `with_view_mut` for you. /// /// [`wrap_impl!`]: ../macro.wrap_impl.html -pub trait ViewWrapper { +pub trait ViewWrapper: 'static { /// Type that this view wraps. type V: View + ?Sized; @@ -96,7 +96,7 @@ pub trait ViewWrapper { // Some types easily implement ViewWrapper. // This includes Box use std::ops::{Deref, DerefMut}; -impl + DerefMut> ViewWrapper for T { +impl + DerefMut + 'static> ViewWrapper for T { type V = U; fn with_view(&self, f: F) -> Option diff --git a/src/views/canvas.rs b/src/views/canvas.rs index 0f84fef..63788ca 100644 --- a/src/views/canvas.rs +++ b/src/views/canvas.rs @@ -173,7 +173,7 @@ impl Canvas { } } -impl View for Canvas { +impl View for Canvas { fn draw(&self, printer: &Printer) { (self.draw)(&self.state, printer); } diff --git a/src/views/id_view.rs b/src/views/id_view.rs index 2bcbafd..5b957da 100644 --- a/src/views/id_view.rs +++ b/src/views/id_view.rs @@ -1,6 +1,7 @@ use owning_ref::{OwningHandle, RcRef}; use std::any::Any; use std::cell::{RefCell, RefMut}; +use std::ops::DerefMut; use std::rc::Rc; use view::{Selector, View, ViewWrapper}; @@ -69,18 +70,14 @@ impl ViewWrapper for IdView { // Whoops! Abort! Undo! self.view = rc; Err(self) - }, - Ok(cell) => { - Ok(cell.into_inner()) } + Ok(cell) => Ok(cell.into_inner()), } } // Some for<'b> weirdness here to please the borrow checker gods... fn wrap_call_on_any<'a>( - &mut self, - selector: &Selector, - mut callback: BoxedCallback<'a>, + &mut self, selector: &Selector, mut callback: BoxedCallback<'a> ) { match selector { &Selector::Id(id) if id == self.id => callback(self), @@ -88,7 +85,7 @@ impl ViewWrapper for IdView { self.view .try_borrow_mut() .ok() - .map(|mut v| v.call_on_any(s, callback)); + .map(|mut v| v.deref_mut().call_on_any(s, callback)); } } } @@ -99,7 +96,7 @@ impl ViewWrapper for IdView { s => self.view .try_borrow_mut() .map_err(|_| ()) - .and_then(|mut v| v.focus_view(s)), + .and_then(|mut v| v.deref_mut().focus_view(s)), } } } diff --git a/src/views/radio.rs b/src/views/radio.rs index f0b1445..6c975cc 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -154,7 +154,7 @@ impl RadioButton { } } -impl View for RadioButton { +impl View for RadioButton { fn required_size(&mut self, _: Vec2) -> Vec2 { self.req_size() }