Skip to content

Commit

Permalink
feat: io_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 11, 2023
1 parent 5512d56 commit 11c870f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: IoFormat>(&self) -> IO<S> {
IO::new_unchecked(self)
}

#[deprecated(note = "renamed to io_bytes")]
pub fn io(&self) -> IO<u8> { IO::new(self) }
pub fn io_bytes(&self) -> IO<u8> { IO::new(self) }
Expand Down Expand Up @@ -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::<S>()) as isize) as alsa::snd_pcm_uframes_t
Expand Down

0 comments on commit 11c870f

Please sign in to comment.