Skip to content

Commit

Permalink
Derive 'Default' for SkipTo
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioGNR committed Dec 14, 2024
1 parent 53faf81 commit f18e41f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
33 changes: 13 additions & 20 deletions connect/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,19 @@ pub enum PlayingTrack {
Uid(String),
}

impl From<Option<SkipTo>> for PlayingTrack {
fn from(value: Option<SkipTo>) -> Self {
match value {
Some(value) => {
// order of checks is important, as the index can be 0, but still has an uid or uri provided,
// so we only use the index as last resort
if let Some(uri) = value.track_uri {
PlayingTrack::Uri(uri)
} else if let Some(uid) = value.track_uid {
PlayingTrack::Uid(uid)
} else {
PlayingTrack::Index(value.track_index.unwrap_or_else(|| {
warn!(
"SkipTo didn't provided any point to skip to, falling back to index 0"
);
0
}))
}
}
None => PlayingTrack::Index(0),
impl From<SkipTo> for PlayingTrack {
fn from(value: SkipTo) -> Self {
// order of checks is important, as the index can be 0, but still has an uid or uri provided,
// so we only use the index as last resort
if let Some(uri) = value.track_uri {
PlayingTrack::Uri(uri)
} else if let Some(uid) = value.track_uid {
PlayingTrack::Uid(uid)
} else {
PlayingTrack::Index(value.track_index.unwrap_or_else(|| {
warn!("SkipTo didn't provided any point to skip to, falling back to index 0");
0
}))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ impl SpircTask {
context_uri: play.context.uri.clone(),
start_playing: true,
seek_to: play.options.seek_to.unwrap_or_default(),
playing_track: play.options.skip_to.into(),
playing_track: play.options.skip_to.unwrap_or_default().into(),
shuffle,
repeat,
repeat_track,
Expand Down
2 changes: 1 addition & 1 deletion core/src/dealer/protocol/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub struct OptionsOptions {
system_initiated: bool,
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, Default)]
pub struct SkipTo {
pub track_uid: Option<String>,
pub track_uri: Option<String>,
Expand Down

0 comments on commit f18e41f

Please sign in to comment.