mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-05 02:39:53 +02:00
Move FileId out of SpotifyId
This commit is contained in:
parent
f03a7e95c1
commit
9b2ca1442e
12 changed files with 108 additions and 68 deletions
55
core/src/file_id.rs
Normal file
55
core/src/file_id.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use librespot_protocol as protocol;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::spotify_id::to_base16;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct FileId(pub [u8; 20]);
|
||||
|
||||
impl FileId {
|
||||
pub fn from_raw(src: &[u8]) -> FileId {
|
||||
let mut dst = [0u8; 20];
|
||||
dst.clone_from_slice(src);
|
||||
FileId(dst)
|
||||
}
|
||||
|
||||
pub fn to_base16(&self) -> String {
|
||||
to_base16(&self.0, &mut [0u8; 40])
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for FileId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_tuple("FileId").field(&self.to_base16()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FileId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(&self.to_base16())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[u8]> for FileId {
|
||||
fn from(src: &[u8]) -> Self {
|
||||
Self::from_raw(src)
|
||||
}
|
||||
}
|
||||
impl From<&protocol::metadata::Image> for FileId {
|
||||
fn from(image: &protocol::metadata::Image) -> Self {
|
||||
Self::from(image.get_file_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&protocol::metadata::AudioFile> for FileId {
|
||||
fn from(file: &protocol::metadata::AudioFile) -> Self {
|
||||
Self::from(file.get_file_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&protocol::metadata::VideoFile> for FileId {
|
||||
fn from(video: &protocol::metadata::VideoFile) -> Self {
|
||||
Self::from(video.get_file_id())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue