AUDIO
Source snapshot · 11 November 2026

API reference / ravet_audio_file::Mp3Writer

Struct Mp3Writer 

pub struct Mp3Writer<W: Write + Seek> { /* private fields */ }
Expand description

Worker-only seekable MP3 writer. New validates a fresh region at current EOF; callers own truncation/concurrent access. All sample-call preflight precedes codec mutation. Explicit finish flushes codec, validates Info/LAME gapless counts, replaces reserved first frame, restores end and flushes destination. Completed files have exact source-frame metadata; gapless-aware file decoders honor it, whereas arbitrary stream players may retain padding. Drop/abort do not write/seek/flush. Sink destructor is caller policy. Backend working memory remains backend-owned, no total-memory or real-time deadline claim.

use ravet_audio_file::{Mp3Bitrate, Mp3Format, Mp3Writer};
use std::io::Cursor;
let format = Mp3Format {channels: 2, sample_rate: 48000,
    bit_rate: Mp3Bitrate::Kbps256};
let mut writer = Mp3Writer::new(Cursor::new(Vec::new()), format, 17, 65536).unwrap();
writer.write_samples(&[0.25_f32; 34]).unwrap();
let complete = writer.finish().unwrap().into_inner();
assert!(!complete.is_empty());

Implementations§

§

impl<W: Write + Seek> Mp3Writer<W>

pub fn new( destination: W, format: Mp3Format, maximum_frames: u64, maximum_written_bytes: u64, ) -> Result<Self, Mp3Failure<W>>

pub fn format(&self) -> Mp3Format

pub fn accepted_frames(&self) -> u64

pub fn file_bytes(&self) -> u64

pub fn written_bytes(&self) -> u64

pub fn failure(&self) -> Option<&Error>

pub fn write_samples( &mut self, samples: &[f32], ) -> Result<usize, Mp3WriteError<'_>>

pub fn finish(self) -> Result<W, Mp3Failure<W>>

Explicitly finalize or return partial sink with retained original error.

pub fn abort(self) -> W

Recover incomplete destination without codec finalization or sink I/O. This convenience abort discards stored error/counts; inspect getters first or finish a poisoned writer to recover original diagnostics without I/O.

Auto Trait Implementations§

§

impl<W> !RefUnwindSafe for Mp3Writer<W>

§

impl<W> !UnwindSafe for Mp3Writer<W>

§

impl<W> Freeze for Mp3Writer<W>
where W: Freeze,

§

impl<W> Send for Mp3Writer<W>
where W: Send,

§

impl<W> Sync for Mp3Writer<W>
where W: Sync,

§

impl<W> Unpin for Mp3Writer<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Mp3Writer<W>
where W: UnsafeUnpin,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

fn into_sample(self) -> T

§

impl<T> Same for T

§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.