-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug Fix: Handle null images for playlist #716
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,7 +186,7 @@ trait WithImages { | |
pub struct Playlist { | ||
pub id: String, | ||
pub name: String, | ||
pub images: Vec<Image>, | ||
pub images: Option<Vec<Image>>, | ||
pub tracks: Page<PlaylistTrack>, | ||
pub owner: PlaylistOwner, | ||
} | ||
|
@@ -197,9 +197,14 @@ pub struct PlaylistOwner { | |
pub display_name: String, | ||
} | ||
|
||
const def_image: &'static [Image] = &[Image {url: String::new(), height: Some(640), width: Some(640)}]; | ||
|
||
impl WithImages for Playlist { | ||
fn images(&self) -> &[Image] { | ||
&self.images | ||
match &self.images { | ||
Some(x) => &x[..], | ||
None => &def_image[..], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we return an empty array here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Rust returns |
||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
#[serde(default)]
fix the issue?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprisingly, no. I haven't investigated why but adding that to the images will still throw a null-errror.