Implement Into ContentState types.

This commit is contained in:
Jordan Petridis 2017-12-07 11:14:12 +02:00
parent 6801d0b1d1
commit 41b0a36b81
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -74,19 +74,20 @@ struct WidgetsView {
content: Content content: Content
} }
impl Empty { #[derive(Debug)]
fn into_podcasts(self) -> Result<PodcastsView, Empty> { pub enum ContentState {
if self.content.podcasts.flowbox.get_children().is_empty() { empty(Empty),
return Err(self); pop(PodcastsView),
} pd(WidgetsView),
}
impl Into<PodcastsView> for Empty {
fn into(self) -> PodcastsView {
self.content.stack.set_visible_child_name("podcasts"); self.content.stack.set_visible_child_name("podcasts");
Ok( PodcastsView {
PodcastsView { content: self.content
content: self.content }
}
)
} }
} }
@ -94,22 +95,17 @@ impl UpdateView for Empty {
fn update(&mut self) {} fn update(&mut self) {}
} }
impl PodcastsView { impl Into<Empty> for PodcastsView {
fn into_empty(self) -> Result<Empty, PodcastsView> { fn into(self) -> Empty {
if !self.content.podcasts.flowbox.get_children().is_empty() {
return Err(self);
}
self.content.stack.set_visible_child_name("empty"); self.content.stack.set_visible_child_name("empty");
Empty {
Ok( content: self.content
Empty { }
content: self.content
}
)
} }
}
fn into_widget(self) -> WidgetsView { impl Into<WidgetsView> for PodcastsView {
fn into(self) -> WidgetsView {
self.content.stack.set_visible_child_name("widget"); self.content.stack.set_visible_child_name("widget");
WidgetsView { WidgetsView {
@ -125,15 +121,17 @@ impl UpdateView for PodcastsView {
} }
} }
impl WidgetsView { impl Into<PodcastsView> for WidgetsView {
fn into_podcasts(self) -> PodcastsView { fn into(self) -> PodcastsView {
self.content.stack.set_visible_child_name("podcasts"); self.content.stack.set_visible_child_name("podcasts");
PodcastsView { PodcastsView {
content: self.content content: self.content
} }
} }
}
fn into_empty(self) -> Empty { impl Into<Empty> for WidgetsView {
fn into(self) -> Empty {
self.content.stack.set_visible_child_name("empty"); self.content.stack.set_visible_child_name("empty");
Empty { Empty {
content: self.content content: self.content
@ -152,13 +150,6 @@ impl UpdateView for WidgetsView {
} }
} }
#[derive(Debug)]
pub enum ContentState {
empty(Empty),
pop(PodcastsView),
pd(WidgetsView),
}
impl ContentState { impl ContentState {
pub fn new() -> ContentState { pub fn new() -> ContentState {
let content = Content::new(); let content = Content::new();