diff --git a/src/pcm.rs b/src/pcm.rs index c39cbce..f340509 100644 --- a/src/pcm.rs +++ b/src/pcm.rs @@ -234,6 +234,13 @@ impl PCM { self.verify_format(S::FORMAT).map(|_| IO::new(self)) } + /// Creates IO without checking [`S`] is valid type. + /// + /// SAFETY: Caller must guarantee [`S`] is valid type for this PCM stream + pub unsafe fn io_unchecked(&self) -> IO { + IO::new_unchecked(self) + } + #[deprecated(note = "renamed to io_bytes")] pub fn io(&self) -> IO { IO::new(self) } pub fn io_bytes(&self) -> IO { IO::new(self) } @@ -359,6 +366,11 @@ impl<'a, S: Copy> IO<'a, S> { IO(a, PhantomData) } + unsafe fn new_unchecked(a: &'a PCM) -> IO<'a, S> { + a.1.set(true); + IO(a, PhantomData) + } + fn to_frames(&self, b: usize) -> alsa::snd_pcm_uframes_t { // TODO: Do we need to check for overflow here? self.0.bytes_to_frames((b * size_of::()) as isize) as alsa::snd_pcm_uframes_t