librespot_metadata/playlist/
diff.rs

1use std::fmt::Debug;
2
3use super::operation::PlaylistOperations;
4
5use librespot_core::SpotifyId;
6
7use librespot_protocol as protocol;
8use protocol::playlist4_external::Diff as DiffMessage;
9
10#[derive(Debug, Clone)]
11pub struct PlaylistDiff {
12    pub from_revision: SpotifyId,
13    pub operations: PlaylistOperations,
14    pub to_revision: SpotifyId,
15}
16
17impl TryFrom<&DiffMessage> for PlaylistDiff {
18    type Error = librespot_core::Error;
19    fn try_from(diff: &DiffMessage) -> Result<Self, Self::Error> {
20        Ok(Self {
21            from_revision: diff
22                .from_revision
23                .clone()
24                .unwrap_or_default()
25                .as_slice()
26                .try_into()?,
27            operations: diff.ops.as_slice().try_into()?,
28            to_revision: diff
29                .to_revision
30                .clone()
31                .unwrap_or_default()
32                .as_slice()
33                .try_into()?,
34        })
35    }
36}