Trait lofty::io::Truncate

source ·
pub trait Truncate {
    type Error: Into<LoftyError>;

    // Required method
    fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>;
}
Expand description

Provides a method to truncate an object to the specified length

This is one component of the FileLike trait, which is used to provide implementors access to any file saving methods such as AudioFile::save_to.

Take great care in implementing this for downstream types, as Lofty will assume that the container has the new length specified. If this assumption were to be broken, files will become corrupted.

§Examples

use lofty::io::Truncate;

let mut data = vec![1, 2, 3, 4, 5];
data.truncate(3);

assert_eq!(data, vec![1, 2, 3]);

Required Associated Types§

source

type Error: Into<LoftyError>

The error type of the truncation operation

Required Methods§

source

fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>

Truncate a storage object to the specified length

§Errors

Errors depend on the object being truncated, which may not always be fallible.

Implementations on Foreign Types§

source§

impl Truncate for VecDeque<u8>

source§

type Error = Infallible

source§

fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>

source§

impl Truncate for Vec<u8>

source§

type Error = Infallible

source§

fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>

source§

impl Truncate for File

source§

type Error = Error

source§

fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>

source§

impl<T> Truncate for &mut T
where T: Truncate,

source§

type Error = <T as Truncate>::Error

source§

fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>

source§

impl<T> Truncate for Box<T>
where T: Truncate,

source§

type Error = <T as Truncate>::Error

source§

fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>

source§

impl<T> Truncate for Cursor<T>
where T: Truncate,

source§

type Error = <T as Truncate>::Error

source§

fn truncate(&mut self, new_len: u64) -> Result<(), Self::Error>

Implementors§