Skip to content

Commit

Permalink
csi/reader: Add common methods to access the underlying reader
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Jun 10, 2024
1 parent acd4756 commit 3a26bdd
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions noodles-csi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Added

* csi/reader: Add common methods to access the underlying reader.

## 0.35.0 - 2024-05-16

### Changed
Expand Down
42 changes: 42 additions & 0 deletions noodles-csi/src/async/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,48 @@ where
}
}

/// Returns a reference to the underlying reader.
///
/// # Examples
///
/// ```
/// use noodles_csi as csi;
/// use tokio::io;
/// let reader = csi::r#async::Reader::new(io::empty());
/// let _inner = reader.get_ref();
/// ```
pub fn get_ref(&self) -> &bgzf::AsyncReader<R> {
&self.inner
}

/// Returns a mutable reference to the underlying reader.
///
/// # Examples
///
/// ```
/// use noodles_csi as csi;
/// use tokio::io;
/// let mut reader = csi::r#async::Reader::new(io::empty());
/// let _inner = reader.get_mut();
/// ```
pub fn get_mut(&mut self) -> &mut bgzf::AsyncReader<R> {
&mut self.inner
}

/// Returns the underlying reader.
///
/// # Examples
///
/// ```
/// use noodles_csi as csi;
/// use tokio::io;
/// let reader = csi::r#async::Reader::new(io::empty());
/// let _inner = reader.into_inner();
/// ```
pub fn into_inner(self) -> bgzf::AsyncReader<R> {
self.inner
}

/// Reads the CSI index.
///
/// The position of the stream is expected to be at the beginning.
Expand Down
44 changes: 44 additions & 0 deletions noodles-csi/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,50 @@ pub struct Reader<R> {
inner: bgzf::Reader<R>,
}

impl<R> Reader<R> {
/// Returns a reference to the underlying reader.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_csi as csi;
/// let reader = csi::Reader::new(io::empty());
/// let _inner = reader.get_ref();
/// ```
pub fn get_ref(&self) -> &bgzf::Reader<R> {
&self.inner
}

/// Returns a mutable reference to the underlying reader.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_csi as csi;
/// let mut reader = csi::Reader::new(io::empty());
/// let _inner = reader.get_mut();
/// ```
pub fn get_mut(&mut self) -> &mut bgzf::Reader<R> {
&mut self.inner
}

/// Returns the underlying reader.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_csi as csi;
/// let reader = csi::Reader::new(io::empty());
/// let _inner = reader.into_inner();
/// ```
pub fn into_inner(self) -> bgzf::Reader<R> {
self.inner
}
}

impl<R> Reader<R>
where
R: Read,
Expand Down

0 comments on commit 3a26bdd

Please sign in to comment.