Skip to content

Commit

Permalink
misc: impl TryFrom<&Value> for Time
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Feb 14, 2024
1 parent 4732d4a commit 4675926
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ impl Metadata {

/// The duration of the track.
pub fn length(&self) -> Option<Time> {
self.get_value("mpris:length")?
.try_clone()
.ok()
.and_then(|v| v.downcast().ok())
self.get_value("mpris:length")?.downcast_ref().ok()
}

/// Sets the duration of the track.
Expand Down
8 changes: 8 additions & 0 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ impl TryFrom<Value<'_>> for Time {
}
}

impl TryFrom<&Value<'_>> for Time {
type Error = Error;

fn try_from(value: &Value<'_>) -> Result<Self, Self::Error> {
i64::try_from(value).map(Self)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 4675926

Please sign in to comment.