Trait lofty::ogg::OggPictureStorage
source · pub trait OggPictureStorage: Sealed {
// Required method
fn pictures(&self) -> &[(Picture, PictureInformation)];
// Provided methods
fn insert_picture(
&mut self,
picture: Picture,
information: Option<PictureInformation>
) -> Result<Option<(Picture, PictureInformation)>> { ... }
fn remove_picture_type(&mut self, picture_type: PictureType) { ... }
fn set_picture(
&mut self,
index: usize,
picture: Picture,
info: PictureInformation
) { ... }
fn remove_picture(&mut self, index: usize) -> (Picture, PictureInformation) { ... }
fn remove_pictures(&mut self) -> Vec<(Picture, PictureInformation)> { ... }
}
Expand description
Defines methods for interacting with an item storing OGG pictures
This exists due to both VorbisComments
and FlacFile
needing to store
pictures in their own ways.
It cannot be implemented downstream.
Required Methods§
Provided Methods§
sourcefn insert_picture(
&mut self,
picture: Picture,
information: Option<PictureInformation>
) -> Result<Option<(Picture, PictureInformation)>>
fn insert_picture( &mut self, picture: Picture, information: Option<PictureInformation> ) -> Result<Option<(Picture, PictureInformation)>>
Inserts a Picture
NOTES:
- If
information
isNone
, thePictureInformation
will be inferred usingPictureInformation::from_picture
. - According to spec, there can only be one picture of type
PictureType::Icon
andPictureType::OtherIcon
. When attempting to insert these types, if another is found it will be removed and returned.
Errors
sourcefn remove_picture_type(&mut self, picture_type: PictureType)
fn remove_picture_type(&mut self, picture_type: PictureType)
Removes a certain PictureType
sourcefn set_picture(
&mut self,
index: usize,
picture: Picture,
info: PictureInformation
)
fn set_picture( &mut self, index: usize, picture: Picture, info: PictureInformation )
Replaces the picture at the given index
NOTE: If index
is out of bounds, the picture
will be appended
to the list.
Examples
use lofty::ogg::{VorbisComments, OggPictureStorage};
let mut tag = VorbisComments::default();
// Add a front cover
tag.insert_picture(front_cover, Some(front_cover_info))?;
assert_eq!(tag.pictures().len(), 1);
assert_eq!(tag.pictures()[0].0.pic_type(), PictureType::CoverFront);
// Replace the front cover with a back cover
tag.set_picture(0, back_cover, back_cover_info);
assert_eq!(tag.pictures().len(), 1);
assert_eq!(tag.pictures()[0].0.pic_type(), PictureType::CoverBack);
// Use an out of bounds index
tag.set_picture(100, another_picture, PictureInformation::default());
assert_eq!(tag.pictures().len(), 2);
sourcefn remove_picture(&mut self, index: usize) -> (Picture, PictureInformation)
fn remove_picture(&mut self, index: usize) -> (Picture, PictureInformation)
Removes and returns the picture at the given index
Panics
Panics if index
is out of bounds.
Examples
use lofty::ogg::{VorbisComments, OggPictureStorage};
let mut tag = VorbisComments::default();
// Add a front cover
tag.insert_picture(front_cover, Some(front_cover_info))?;
assert_eq!(tag.pictures().len(), 1);
tag.remove_picture(0);
assert_eq!(tag.pictures().len(), 0);
sourcefn remove_pictures(&mut self) -> Vec<(Picture, PictureInformation)>
fn remove_pictures(&mut self) -> Vec<(Picture, PictureInformation)>
Removes all pictures and returns them
Examples
use lofty::ogg::{VorbisComments, OggPictureStorage};
let mut tag = VorbisComments::default();
// Add front and back covers
tag.insert_picture(front_cover, Some(front_cover_info))?;
tag.insert_picture(back_cover, Some(front_cover_info))?;
assert_eq!(tag.pictures().len(), 2);
let pictures = tag.remove_pictures();
assert_eq!(pictures.len(), 2);
// The tag no longer contains any pictures
assert_eq!(tag.pictures().len(), 0);