#[derive(Clone, Debug)]
pub struct AttachedPicture {
pub mime_type: String,
pub picture_type: PictureType,
pub description: String,
pub data: Vec<u8>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
#[repr(u8)]
pub enum PictureType {
Other = 0x00,
FileIcon32x32 = 0x01,
FileIcon = 0x02,
FrontCover = 0x03,
BackCover = 0x04,
LeafletPage = 0x05,
Media = 0x06,
LeadArtist = 0x07,
Artist = 0x08,
Conductor = 0x09,
BandOrchestra = 0x0A,
Composer = 0x0B,
Lyricist = 0x0C,
RecordingLocation = 0x0D,
DuringRecording = 0x0E,
DuringPerformance = 0x0F,
MovieScreenCapture = 0x10,
ABrightColouredFish = 0x11,
Illustration = 0x12,
BandLogo = 0x13,
PublisherLogo = 0x14,
Unknown = 0xFF,
}
impl PictureType {
pub fn from_u8(b: u8) -> Self {
match b {
0x00 => Self::Other,
0x01 => Self::FileIcon32x32,
0x02 => Self::FileIcon,
0x03 => Self::FrontCover,
0x04 => Self::BackCover,
0x05 => Self::LeafletPage,
0x06 => Self::Media,
0x07 => Self::LeadArtist,
0x08 => Self::Artist,
0x09 => Self::Conductor,
0x0A => Self::BandOrchestra,
0x0B => Self::Composer,
0x0C => Self::Lyricist,
0x0D => Self::RecordingLocation,
0x0E => Self::DuringRecording,
0x0F => Self::DuringPerformance,
0x10 => Self::MovieScreenCapture,
0x11 => Self::ABrightColouredFish,
0x12 => Self::Illustration,
0x13 => Self::BandLogo,
0x14 => Self::PublisherLogo,
_ => Self::Unknown,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn picture_type_known_values() {
assert_eq!(PictureType::from_u8(0x03), PictureType::FrontCover);
assert_eq!(PictureType::from_u8(0x07), PictureType::LeadArtist);
assert_eq!(PictureType::from_u8(0x14), PictureType::PublisherLogo);
}
#[test]
fn picture_type_unknown_collapses() {
assert_eq!(PictureType::from_u8(0x15), PictureType::Unknown);
assert_eq!(PictureType::from_u8(0xAB), PictureType::Unknown);
}
}