Struct rotary::io::ReadWrite [−][src]
Make any mutable buffer into a write adapter that implements ReadBuf and 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 to = rotary::interleaved![[0.0f32; 4]; 2]; // Make `to` into a read / write adapter. let mut to = io::ReadWrite::new(to); io::copy_remaining(io::Read::new((&from).skip(2).limit(1)), &mut to); assert_eq!(to.remaining(), 1); io::copy_remaining(io::Read::new((&from).limit(1)), &mut to); assert_eq!(to.remaining(), 2); assert_eq! { to.as_ref().as_slice(), &[3.0, 3.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0], }; // Note: 4 channels, 2 frames each. let mut read_out = io::Write::new(rotary::Interleaved::with_topology(4, 2)); assert_eq!(read_out.remaining_mut(), 2); assert!(read_out.has_remaining_mut()); assert_eq!(to.remaining(), 2); assert!(to.has_remaining()); io::copy_remaining(&mut to, &mut read_out); assert_eq!(read_out.remaining_mut(), 0); assert!(!read_out.has_remaining_mut()); assert_eq!(to.remaining(), 0); assert!(!to.has_remaining()); assert_eq! { read_out.as_ref().as_slice(), &[3.0, 3.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0], }
Implementations
impl<B> ReadWrite<B>
[src]
pub fn new(buf: B) -> Self
[src]
Construct a new read / write buffer around an audio buffer.
pub fn as_ref(&self) -> &B
[src]
Access 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::ReadWrite::new(buffer); let from = rotary::wrap::interleaved(&[1i16, 2i16, 3i16, 4i16][..], 2); io::translate_remaining(from, &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::Buf as _; use rotary::io; let buffer: rotary::Interleaved<i16> = rotary::interleaved![[1, 2, 3, 4]; 4]; let mut buffer = io::ReadWrite::new(buffer); let from = rotary::wrap::interleaved(&[1i16, 2i16, 3i16, 4i16][..], 2); io::translate_remaining(from, &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::ReadWrite::new(buffer); let from = rotary::wrap::interleaved(&[1i16, 2i16, 3i16, 4i16][..], 2); io::translate_remaining(from, &mut buffer); let buffer = buffer.into_inner(); assert_eq!(buffer.channels(), 4);
pub fn clear(&mut self)
[src]
Clear the state of the read / write adapter, setting both read and written to zero.
pub fn set_read(&mut self, read: usize)
[src]
Set the number of frames which have been read.
This is clamped to always be < written.
pub fn set_written(&mut self, written: usize)
[src]
Set the number of frames which have been written.
Trait Implementations
impl<B, T> Buf<T> for ReadWrite<B> where
B: Buf<T>,
[src]
B: Buf<T>,
fn frames_hint(&self) -> Option<usize>
[src]
fn channels(&self) -> usize
[src]
fn channel(&self, channel: usize) -> Channel<'_, T>
[src]
pub fn skip(self, n: usize) -> Skip<Self>
[src]
pub fn tail(self, n: usize) -> Tail<Self>
[src]
pub fn limit(self, limit: usize) -> Limit<Self>
[src]
pub fn chunk(self, n: usize, len: usize) -> Chunk<Self>
[src]
impl<B, T> BufMut<T> for ReadWrite<B> where
B: ExactSizeBuf + BufMut<T>,
[src]
B: ExactSizeBuf + BufMut<T>,
fn channel_mut(&mut self, channel: usize) -> ChannelMut<'_, T>
[src]
impl<B> ExactSizeBuf for ReadWrite<B> where
B: ExactSizeBuf,
[src]
B: ExactSizeBuf,
impl<B> ReadBuf for ReadWrite<B>
[src]
fn remaining(&self) -> usize
[src]
fn advance(&mut self, n: usize)
[src]
pub fn has_remaining(&self) -> bool
[src]
impl<B> WriteBuf for ReadWrite<B> where
B: ExactSizeBuf,
[src]
B: ExactSizeBuf,
fn remaining_mut(&self) -> usize
[src]
fn advance_mut(&mut self, n: usize)
[src]
pub fn has_remaining_mut(&self) -> bool
[src]
Auto Trait Implementations
impl<B> RefUnwindSafe for ReadWrite<B> where
B: RefUnwindSafe,
B: RefUnwindSafe,
impl<B> Send for ReadWrite<B> where
B: Send,
B: Send,
impl<B> Sync for ReadWrite<B> where
B: Sync,
B: Sync,
impl<B> Unpin for ReadWrite<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for ReadWrite<B> where
B: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,