Skip to content

Commit

Permalink
fasta/fai/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 9, 2024
1 parent ce7e587 commit fe85280
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
3 changes: 1 addition & 2 deletions noodles-fasta/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

### Added

* fasta/fai/writer: Add common methods to access the underlying writer
(`Writer::get_mut` and `Writer::into_inner`) ([#269]).
* fasta/fai: Add common methods to access the underlying I/O ([#269]).

[#269]: https://github.com/zaeleus/noodles/issues/269

Expand Down
44 changes: 44 additions & 0 deletions noodles-fasta/src/fai/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,50 @@ pub struct Reader<R> {
inner: R,
}

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

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

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

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

0 comments on commit fe85280

Please sign in to comment.