2016-08-04 04:55:41 +00:00
|
|
|
use view::View;
|
2017-02-08 23:20:41 +00:00
|
|
|
use views::{IdView, RefCellView};
|
2016-08-04 04:55:41 +00:00
|
|
|
|
|
|
|
/// Makes a view wrappable in an [`IdView`].
|
|
|
|
///
|
|
|
|
/// [`IdView`]: ../views/struct.IdView.html
|
|
|
|
pub trait Identifiable: View + Sized {
|
2017-02-08 23:20:41 +00:00
|
|
|
/// Wraps this view into an `IdView` with the given id.
|
2016-09-21 01:32:31 +00:00
|
|
|
///
|
|
|
|
/// This is just a shortcut for `IdView::new(id, self)`
|
2016-08-04 04:55:41 +00:00
|
|
|
fn with_id(self, id: &str) -> IdView<Self> {
|
|
|
|
IdView::new(id, self)
|
|
|
|
}
|
2017-02-08 23:20:41 +00:00
|
|
|
|
|
|
|
/// Wraps this view into both a [`RefCellView`] and an `IdView`.
|
|
|
|
///
|
|
|
|
/// This allows to call [`Cursive::find_id_mut`].
|
|
|
|
///
|
|
|
|
/// [`RefCellView`]: ../views/struct.RefCellView.html
|
|
|
|
/// [`Cursive::find_id_mut`]: ../struct.Cursive.html#method.find_id_mut
|
|
|
|
fn with_id_mut(self, id: &str) -> IdView<RefCellView<Self>> {
|
|
|
|
RefCellView::new(self).with_id(id)
|
|
|
|
}
|
2016-08-04 04:55:41 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 01:32:31 +00:00
|
|
|
/// Any `View` implements this trait.
|
2016-08-04 04:55:41 +00:00
|
|
|
impl<T: View> Identifiable for T {}
|