Struct rotary::io::Write[][src]

pub struct Write<B> { /* fields omitted */ }

Make a mutable buffer into a write adapter that implements WriteBuf.

Examples

use rotary::{Buf as _, ReadBuf as _, WriteBuf as _};
use rotary::io;

let from = rotary::interleaved![[1.0f32, 2.0f32, 3.0f32, 4.0f32]; 2];
let mut from = io::Read::new(from.skip(2));

let to = rotary::interleaved![[0.0f32; 4]; 2];
let mut to = io::Write::new(to);

assert_eq!(to.remaining_mut(), 4);
io::copy_remaining(from, &mut to);
assert_eq!(to.remaining_mut(), 2);

assert_eq! {
    to.as_ref().as_slice(),
    &[3.0, 3.0, 4.0, 4.0, 0.0, 0.0, 0.0, 0.0],
};

Implementations

impl<B> Write<B>[src]

pub fn new(buf: B) -> Self where
    B: ExactSizeBuf
[src]

Construct a new writing adapter.

The constructed writer will be initialized so that the number of bytes available for writing are equal to what’s reported by ExactSizeBuf::frames.

Examples

use rotary::{WriteBuf, ExactSizeBuf};
use rotary::io;

let buffer = rotary::interleaved![[1, 2, 3, 4], [5, 6, 7, 8]];
assert_eq!(buffer.frames(), 4);

let buffer = io::Write::new(buffer);

assert!(buffer.has_remaining_mut());
assert_eq!(buffer.remaining_mut(), 4);

pub fn empty(buf: B) -> Self[src]

Construct a new writing adapter.

The constructed reader will be initialized so that there are no frames available to be written.

Examples

use rotary::{WriteBuf, ExactSizeBuf};
use rotary::io;

let buffer = rotary::interleaved![[1, 2, 3, 4], [5, 6, 7, 8]];
assert_eq!(buffer.frames(), 4);

let buffer = io::Write::empty(buffer);

assert!(!buffer.has_remaining_mut());
assert_eq!(buffer.remaining_mut(), 0);

pub fn as_ref(&self) -> &B[src]

Access the underlying buffer.

Examples

use rotary::{io, wrap};

let buffer: rotary::Interleaved<i16> = rotary::interleaved![[1, 2, 3, 4]; 4];
let mut buffer = io::Write::new(buffer);

io::copy_remaining(wrap::interleaved(&[0i16; 16][..], 4), &mut buffer);

assert_eq!(buffer.as_ref().channels(), 4);

pub fn as_mut(&mut self) -> &mut B[src]

Access the underlying buffer mutably.

Examples

use rotary::{io, wrap};
use rotary::Buf as _;

let buffer: rotary::Interleaved<i16> = rotary::interleaved![[1, 2, 3, 4]; 4];
let mut buffer = io::Write::new(buffer);

io::copy_remaining(wrap::interleaved(&[0i16; 16][..], 4), &mut buffer);

buffer.as_mut().resize_channels(2);

assert_eq!(buffer.channels(), 2);

pub fn into_inner(self) -> B[src]

Convert into the underlying buffer.

Examples

use rotary::Buf as _;
use rotary::io;

let buffer: rotary::Interleaved<i16> = rotary::interleaved![[1, 2, 3, 4]; 4];
let mut buffer = io::Write::new(buffer);

io::copy_remaining(rotary::wrap::interleaved(&[0i16; 16][..], 4), &mut buffer);

let buffer = buffer.into_inner();

assert_eq!(buffer.channels(), 4);

pub fn set_written(&mut self, written: usize) where
    B: ExactSizeBuf
[src]

Set the number of frames written.

This can be used to rewind the internal cursor to a previously written frame if needed. Or, if the underlying buffer has changed for some reason, like if it was read into through a call to Write::as_mut.

Examples

use rotary::{Buf, ChannelsMut, WriteBuf};
use rotary::io;

fn write_to_buf(mut write: impl Buf + ChannelsMut<i16> + WriteBuf) {
    let mut from = rotary::interleaved![[0; 4]; 2];
    io::copy_remaining(io::Read::new(&mut from), write);
}

let mut buffer = io::Write::new(rotary::interleaved![[1, 2, 3, 4], [5, 6, 7, 8]]);
write_to_buf(&mut buffer);

assert!(!buffer.has_remaining_mut());

buffer.set_written(0);

assert!(buffer.has_remaining_mut());

Trait Implementations

impl<B> Buf for Write<B> where
    B: Buf
[src]

impl<B, T> Channels<T> for Write<B> where
    B: Channels<T>, 
[src]

impl<B, T> ChannelsMut<T> for Write<B> where
    B: ChannelsMut<T>, 
[src]

impl<B> ExactSizeBuf for Write<B> where
    B: ExactSizeBuf
[src]

impl<B> WriteBuf for Write<B>[src]

fn remaining_mut(&self) -> usize[src]

Remaining number of frames available.

Auto Trait Implementations

impl<B> RefUnwindSafe for Write<B> where
    B: RefUnwindSafe

impl<B> Send for Write<B> where
    B: Send

impl<B> Sync for Write<B> where
    B: Sync

impl<B> Unpin for Write<B> where
    B: Unpin

impl<B> UnwindSafe for Write<B> where
    B: UnwindSafe

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, 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.