Struct audio::io::Read [−][src]
Make a buffer into a read adapter that implements ReadBuf.
Examples
use audio::Buf; use audio::io; let from = audio::interleaved![[1, 2, 3, 4]; 2]; let mut to = audio::interleaved![[0; 4]; 2]; let mut to = io::ReadWrite::empty(to); io::copy_remaining(io::Read::new((&from).skip(2).limit(1)), &mut to); io::copy_remaining(io::Read::new((&from).limit(1)), &mut to); assert_eq!(to.as_ref().as_slice(), &[3, 3, 1, 1, 0, 0, 0, 0]);
Implementations
impl<B> Read<B>[src]
pub fn new(buf: B) -> Self where
B: ExactSizeBuf, [src]
B: ExactSizeBuf,
Construct a new reading adapter.
The constructed reader will be initialized so that the number of bytes available for reading are equal to what’s reported by ExactSizeBuf::frames.
Examples
use audio::{ReadBuf, ExactSizeBuf}; use audio::io; let buffer = audio::interleaved![[1, 2, 3, 4], [5, 6, 7, 8]]; assert_eq!(buffer.frames(), 4); let buffer = io::Read::new(buffer); assert!(buffer.has_remaining()); assert_eq!(buffer.remaining(), 4);
pub fn empty(buf: B) -> Self[src]
Construct a new reading adapter.
The constructed reader will be initialized so that there are no frames available for reading.
Examples
use audio::{ReadBuf, ExactSizeBuf}; use audio::io; let buffer = audio::interleaved![[1, 2, 3, 4], [5, 6, 7, 8]]; assert_eq!(buffer.frames(), 4); let buffer = io::Read::empty(buffer); assert!(!buffer.has_remaining()); assert_eq!(buffer.remaining(), 0);
pub fn as_ref(&self) -> &B[src]
Access the underlying buffer.
Examples
use audio::Buf; use audio::{io, wrap}; let from: audio::Interleaved<i16> = audio::interleaved![[1, 2, 3, 4]; 4]; let mut from = io::Read::new(from); io::copy_remaining(&mut from, wrap::interleaved(&mut [0i16; 16][..], 4)); assert_eq!(from.as_ref().channels(), 4);
pub fn as_mut(&mut self) -> &mut B[src]
Access the underlying buffer mutably.
Examples
use audio::Buf; use audio::{io, wrap}; let from: audio::Interleaved<i16> = audio::interleaved![[1, 2, 3, 4]; 4]; let mut from = io::Read::new(from); io::copy_remaining(&mut from, wrap::interleaved(&mut [0i16; 16][..], 4)); from.as_mut().resize_channels(2); assert_eq!(from.channels(), 2);
pub fn into_inner(self) -> B[src]
Convert into the underlying buffer.
Examples
use audio::Buf; use audio::{io, wrap}; let from: audio::Interleaved<i16> = audio::interleaved![[1, 2, 3, 4]; 4]; let mut from = io::Read::new(from); io::copy_remaining(&mut from, wrap::interleaved(&mut [0i16; 16][..], 4)); let from = from.into_inner(); assert_eq!(from.channels(), 4);
pub fn set_read(&mut self, read: usize) where
B: ExactSizeBuf, [src]
B: ExactSizeBuf,
Set the number of frames read.
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 written to through a call to Read::as_mut.
Examples
use audio::{Buf, Channels, ReadBuf}; use audio::io; fn read_from_buf(mut read: impl Buf + Channels<i16> + ReadBuf) { let mut out = audio::interleaved![[0; 4]; 2]; io::copy_remaining(read, io::Write::new(&mut out)); } let mut buffer = io::Read::new(audio::interleaved![[1, 2, 3, 4], [5, 6, 7, 8]]); read_from_buf(&mut buffer); assert!(!buffer.has_remaining()); buffer.set_read(0); assert!(buffer.has_remaining());
Trait Implementations
impl<B> Buf for Read<B> where
B: Buf, [src]
B: Buf,
fn frames_hint(&self) -> Option<usize>[src]
fn channels(&self) -> usize[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> Channels<T> for Read<B> where
B: Channels<T>, [src]
B: Channels<T>,
impl<B> ExactSizeBuf for Read<B> where
B: ExactSizeBuf, [src]
B: ExactSizeBuf,
impl<B> ReadBuf for Read<B>[src]
Auto Trait Implementations
impl<B> RefUnwindSafe for Read<B> where
B: RefUnwindSafe,
B: RefUnwindSafe,
impl<B> Send for Read<B> where
B: Send,
B: Send,
impl<B> Sync for Read<B> where
B: Sync,
B: Sync,
impl<B> Unpin for Read<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for Read<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>,