add type coercion helper to ListItem objects

This commit is contained in:
Henrik Friedrichsen
2019-06-09 23:57:47 +02:00
parent b59e9b38e6
commit 96a0e9f9d6
5 changed files with 18 additions and 0 deletions

View File

@@ -150,6 +150,10 @@ impl ListItem for Album {
} }
} }
fn as_listitem(&self) -> Box<ListItem> {
Box::new(self.clone())
}
fn display_left(&self) -> String { fn display_left(&self) -> String {
format!("{}", self) format!("{}", self)
} }

View File

@@ -139,6 +139,10 @@ impl ListItem for Artist {
} }
} }
fn as_listitem(&self) -> Box<ListItem> {
Box::new(self.clone())
}
fn display_left(&self) -> String { fn display_left(&self) -> String {
format!("{}", self) format!("{}", self)
} }

View File

@@ -107,6 +107,10 @@ impl ListItem for Playlist {
} }
} }
fn as_listitem(&self) -> Box<ListItem> {
Box::new(self.clone())
}
fn display_left(&self) -> String { fn display_left(&self) -> String {
self.name.clone() self.name.clone()
} }

View File

@@ -151,6 +151,10 @@ impl ListItem for Track {
current.map(|t| t.id == self.id).unwrap_or(false) current.map(|t| t.id == self.id).unwrap_or(false)
} }
fn as_listitem(&self) -> Box<ListItem> {
Box::new(self.clone())
}
fn display_left(&self) -> String { fn display_left(&self) -> String {
format!("{}", self) format!("{}", self)
} }

View File

@@ -28,6 +28,8 @@ pub trait ListItem: Sync + Send + 'static {
fn artist(&self) -> Option<Artist> { fn artist(&self) -> Option<Artist> {
None None
} }
fn as_listitem(&self) -> Box<ListItem>;
} }
pub trait ViewExt: View { pub trait ViewExt: View {