Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow borrowing the underlying reader for rbsp::ByteReader #61

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/rbsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ impl<R: BufRead> ByteReader<R> {
}
Ok(true)
}

/// Borrows the underlying reader
pub fn reader(&mut self) -> &mut R {
&mut self.inner
}
}
impl<R: BufRead> Read for ByteReader<R> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
Expand Down Expand Up @@ -259,6 +264,15 @@ impl<R: std::io::BufRead + Clone> BitReader<R> {
pub fn reader(&mut self) -> Option<&mut R> {
self.reader.reader()
}

/// Unwraps internal reader and disposes of BitReader.
///
/// # Warning
///
/// Any unread partial bits are discarded.
pub fn into_reader(self) -> R {
self.reader.into_reader()
}
}

impl<R: std::io::BufRead + Clone> BitRead for BitReader<R> {
Expand Down