[][src]Struct metaflac::Tag

pub struct Tag { /* fields omitted */ }

A structure representing a flac metadata tag.

Methods

impl<'a> Tag[src]

pub fn new() -> Tag[src]

Creates a new FLAC tag with no blocks.

pub fn push_block(&mut self, block: Block)[src]

Adds a block to the tag.

pub fn blocks(&'a self) -> impl Iterator<Item = &'a Block> + 'a[src]

Returns a reference to the blocks in the tag.

pub fn get_blocks(
    &'a self,
    block_type: BlockType
) -> impl Iterator<Item = &'a Block> + 'a
[src]

Returns references to the blocks with the specified type.

pub fn remove_blocks(&mut self, block_type: BlockType)[src]

Removes blocks with the specified type.

Example

use metaflac::{Tag, Block, BlockType};

let mut tag = Tag::new();
tag.push_block(Block::Padding(10));
tag.push_block(Block::Unknown((20, Vec::new())));
tag.push_block(Block::Padding(15));

tag.remove_blocks(BlockType::Padding);
assert_eq!(tag.blocks().count(), 1);

pub fn vorbis_comments(&self) -> Option<&VorbisComment>[src]

Returns a reference to the first vorbis comment block. Returns None if no vorbis comment blocks are found.

Example

use metaflac::Tag;

let mut tag = Tag::new();
assert!(tag.vorbis_comments().is_none());

tag.set_vorbis("key", vec!("value"));

assert!(tag.vorbis_comments().is_some());

pub fn vorbis_comments_mut(&mut self) -> &mut VorbisComment[src]

Returns a mutable reference to the first vorbis comment block. If no block is found, a new vorbis comment block is added to the tag and a reference to the newly added block is returned.

Example

use metaflac::Tag;

let mut tag = Tag::new();
assert!(tag.vorbis_comments().is_none());

let key = "key".to_owned();
let value1 = "value1".to_owned();
let value2 = "value2".to_owned();

tag.vorbis_comments_mut().comments.insert(key.clone(), vec!(value1.clone(),
    value2.clone()));

assert!(tag.vorbis_comments().is_some());
assert!(tag.vorbis_comments().unwrap().comments.get(&key).is_some());

pub fn get_vorbis(
    &'a self,
    key: &str
) -> Option<impl Iterator<Item = &'a str> + 'a>
[src]

Returns a vector of strings values for the specified vorbis comment key. Returns None if the tag does not contain a vorbis comment or if the vorbis comment does not contain a comment with the specified key.

Example

use metaflac::Tag;

let mut tag = Tag::new();

let key = "key".to_owned();
let value1 = "value1".to_owned();
let value2 = "value2".to_owned();

tag.set_vorbis(&key[..], vec!(&value1[..], &value2[..]));

assert_eq!(tag.get_vorbis(&key).unwrap().collect::<Vec<_>>(), &[&value1[..], &value2[..]]);

pub fn set_vorbis<K: Into<String>, V: Into<String>>(
    &mut self,
    key: K,
    values: Vec<V>
)
[src]

Sets the values for the specified vorbis comment key.

Example

use metaflac::Tag;

let mut tag = Tag::new();

let key = "key".to_owned();
let value1 = "value1".to_owned();
let value2 = "value2".to_owned();

tag.set_vorbis(&key[..], vec!(&value1[..], &value2[..]));

assert_eq!(tag.get_vorbis(&key).unwrap().collect::<Vec<_>>(), &[&value1[..], &value2[..]]);

pub fn remove_vorbis(&mut self, key: &str)[src]

Removes the values for the specified vorbis comment key.

Example

use metaflac::Tag;

let mut tag = Tag::new();

let key = "key".to_owned();
let value1 = "value1".to_owned();
let value2 = "value2".to_owned();

tag.set_vorbis(&key[..], vec!(&value1[..], &value2[..]));
assert_eq!(tag.get_vorbis(&key).unwrap().collect::<Vec<_>>(), &[&value1[..], &value2[..]]);

tag.remove_vorbis(&key);
assert!(tag.get_vorbis(&key).is_none());

pub fn remove_vorbis_pair(&mut self, key: &str, value: &str)[src]

Removes the vorbis comments with the specified key and value.

Example

use metaflac::Tag;

let mut tag = Tag::new();

let key = "key".to_owned();
let value1 = "value1".to_owned();
let value2 = "value2".to_owned();

tag.set_vorbis(key.clone(), vec!(&value1[..], &value2[..]));
assert_eq!(tag.get_vorbis(&key).unwrap().collect::<Vec<_>>(), &[&value1[..], &value2[..]]);

tag.remove_vorbis_pair(&key, &value1);
assert_eq!(tag.get_vorbis(&key).unwrap().collect::<Vec<_>>(), &[&value2[..]]);

pub fn pictures(&'a self) -> impl Iterator<Item = &'a Picture> + 'a[src]

Returns a vector of references to the pictures in the tag.

Example

use metaflac::Tag;
use metaflac::block::PictureType::CoverFront;

let mut tag = Tag::new();
assert_eq!(tag.pictures().count(), 0);

tag.add_picture("image/jpeg", CoverFront, vec!(0xFF));

assert_eq!(tag.pictures().count(), 1);

pub fn add_picture<T: Into<String>>(
    &mut self,
    mime_type: T,
    picture_type: PictureType,
    data: Vec<u8>
)
[src]

Adds a picture block.

Example

use metaflac::Tag;
use metaflac::block::PictureType::CoverFront;

let mut tag = Tag::new();
assert_eq!(tag.pictures().count(), 0);

tag.add_picture("image/jpeg", CoverFront, vec!(0xFF));

let picture = tag.pictures().next().unwrap();
assert_eq!(&picture.mime_type[..], "image/jpeg");
assert_eq!(picture.picture_type, CoverFront);
assert_eq!(&picture.data[..], &vec!(0xFF)[..]);

pub fn remove_picture_type(&mut self, picture_type: PictureType)[src]

Removes the picture with the specified picture type.

Example

use metaflac::Tag;
use metaflac::block::PictureType::{CoverFront, Other};

let mut tag = Tag::new();
assert_eq!(tag.pictures().count(), 0);

tag.add_picture("image/jpeg", CoverFront, vec!(0xFF));
tag.add_picture("image/png", Other, vec!(0xAB));
assert_eq!(tag.pictures().count(), 2);

tag.remove_picture_type(CoverFront);
assert_eq!(tag.pictures().count(), 1);

let picture = tag.pictures().next().unwrap();
assert_eq!(&picture.mime_type[..], "image/png");
assert_eq!(picture.picture_type, Other);
assert_eq!(&picture.data[..], &vec!(0xAB)[..]);

pub fn save(&mut self) -> Result<()>[src]

Attempts to save the tag back to the file which it was read from. An Error::InvalidInput will be returned if this is called on a tag which was not read from a file.

pub fn skip_metadata<R: Read + Seek>(reader: &mut R) -> Vec<u8>[src]

Returns the contents of the reader without any FLAC metadata.

pub fn is_candidate<R: Read + Seek>(reader: &mut R) -> bool[src]

Will return true if the reader is a candidate for FLAC metadata. The reader position will be reset back to the previous position before returning.

pub fn read_from(reader: &mut dyn Read) -> Result<Tag>[src]

Attempts to read a FLAC tag from the reader.

pub fn write_to(&mut self, writer: &mut dyn Write) -> Result<()>[src]

Attempts to write the FLAC tag to the writer.

pub fn write_to_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()>[src]

Attempts to write the FLAC tag to a file at the indicated path. If the specified path is the same path which the tag was read from, then the tag will be written to the padding if possible.

pub fn read_from_path<P: AsRef<Path>>(path: P) -> Result<Tag>[src]

Attempts to read a FLAC tag from the file at the specified path.

Trait Implementations

impl Clone for Tag[src]

Auto Trait Implementations

impl RefUnwindSafe for Tag

impl Send for Tag

impl Sync for Tag

impl Unpin for Tag

impl UnwindSafe for Tag

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.