Skip to main content

WriteOptions

Struct WriteOptions 

Source
#[non_exhaustive]
pub struct WriteOptions { /* private fields */ }
Expand description

Options to control how Lofty writes to a file

This acts as a dumping ground for all sorts of format-specific settings. As such, this is best used as an application global config that gets set once.

Implementations§

Source§

impl WriteOptions

Source

pub const DEFAULT_PREFERRED_PADDING: u32 = 1024

Default preferred padding size in bytes

Source

pub const fn new() -> WriteOptions

Creates a new WriteOptions, alias for Default implementation

See also: WriteOptions::default

§Examples
use lofty::config::WriteOptions;

let write_options = WriteOptions::new();
Source

pub fn preferred_padding(self, preferred_padding: u32) -> WriteOptions

Set the preferred padding size in bytes

If the tag format being written supports padding, this will be the size of the padding in bytes.

NOTES:

  • Not all tag formats support padding
  • The actual padding size may be different from this value, depending on tag size limitations
§Examples
use lofty::config::WriteOptions;

// I really don't want my files rewritten, so I'll double the padding size!
let options = WriteOptions::new().preferred_padding(2048);

// ...Or I don't want padding under any circumstances!
let options = WriteOptions::new().preferred_padding(0);
Source

pub fn remove_others(self, remove_others: bool) -> WriteOptions

Whether to remove all other tags when writing

If set to true, only the tag being written will be kept in the file.

§Examples
use lofty::config::WriteOptions;
use lofty::prelude::*;
use lofty::tag::{Tag, TagType};

let mut id3v2_tag = Tag::new(TagType::Id3v2);

// ...

// I only want to keep the ID3v2 tag around!
let options = WriteOptions::new().remove_others(true);
id3v2_tag.save_to_path("test.mp3", options)?;
Source

pub fn respect_read_only(self, respect_read_only: bool) -> WriteOptions

Whether to respect read-only tag items

Some tag formats allow for items to be marked as read-only. If set to true, these items will take priority over newly created tag items.

NOTE: In the case of APE tags, one can mark the entire tag as read-only. This will append the existing tag items to the new tag.

§Examples
use lofty::config::WriteOptions;
use lofty::prelude::*;
use lofty::tag::{Tag, TagType};

let mut id3v2_tag = Tag::new(TagType::Id3v2);

// ...

// I don't care about read-only items, I want to write my new items!
let options = WriteOptions::new().respect_read_only(false);
id3v2_tag.save_to_path("test.mp3", options)?;
Source

pub fn uppercase_id3v2_chunk(self, uppercase_id3v2_chunk: bool) -> WriteOptions

Whether to uppercase the ID3v2 chunk name

When dealing with RIFF/AIFF files, some software may expect the ID3v2 chunk name to be lowercase.

NOTE: The vast majority of software will be able to read both upper and lowercase chunk names.

§Examples
use lofty::config::WriteOptions;
use lofty::prelude::*;
use lofty::tag::{Tag, TagType};

let mut id3v2_tag = Tag::new(TagType::Id3v2);

// ...

// I want to keep the ID3v2 chunk name lowercase
let options = WriteOptions::new().uppercase_id3v2_chunk(false);
id3v2_tag.save_to_path("test.mp3", options)?;
Source

pub fn use_id3v23(&mut self, use_id3v23: bool) -> WriteOptions

Whether or not to use ID3v2.3 when saving TagType::Id3v2 or Id3v2Tag

By default, Lofty will save ID3v2.4 tags. This option allows you to save ID3v2.3 tags instead.

§Examples
use lofty::config::WriteOptions;
use lofty::prelude::*;
use lofty::tag::{Tag, TagType};

let mut id3v2_tag = Tag::new(TagType::Id3v2);

// ...

// I need to save ID3v2.3 tags to support older software
let options = WriteOptions::new().use_id3v23(true);
id3v2_tag.save_to_path("test.mp3", options)?;
Source

pub fn lossy_text_encoding(&mut self, lossy_text_encoding: bool) -> WriteOptions

Whether to replace invalid characters when writing strings

Some tag formats are restricted to certain TextEncodings, which may restrict the available character set.

If this is enabled, any invalid characters will be replaced with '?' (e.g lфfty in TextEncoding::Latin1 will return l?fty).

If this is disabled, any writes with non-representable characters will return an ErrorKind::TextEncode.

§Examples
use lofty::config::WriteOptions;
use lofty::prelude::*;
use lofty::tag::{Tag, TagType};

let mut id3v1_tag = Tag::new(TagType::Id3v1);

// ID3v1 is restricted to Latin-1, this string can't be written as-is!
id3v1_tag.insert_text(ItemKey::TrackArtist, String::from("lфfty"));

// With lossy encoding disabled, the write will fail!
let options = WriteOptions::new().lossy_text_encoding(false);
id3v1_tag.save_to_path("test.mp3", options)?;

Trait Implementations§

Source§

impl Clone for WriteOptions

Source§

fn clone(&self) -> WriteOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WriteOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for WriteOptions

Source§

fn default() -> WriteOptions

The default implementation for WriteOptions

The defaults are as follows:

WriteOptions {
    preferred_padding: 1024,
    remove_others: false,
    respect_read_only: true,
    uppercase_id3v2_chunk: true,
    use_id3v23: false,
    lossy_text_encoding: true,
}
Source§

impl PartialEq for WriteOptions

Source§

fn eq(&self, other: &WriteOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for WriteOptions

Source§

impl Eq for WriteOptions

Source§

impl StructuralPartialEq for WriteOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,