Skip to content

Commit

Permalink
fix: add get_ref/get_mut/into_inner for noodles-vcf (#211)
Browse files Browse the repository at this point in the history
* fix: add get_ref/get_mut/into_inner for noodles-vcf

* vcf/async: Fix underlying I/O access examples

* vcf/changelog: Add entries for underlying I/O access

---------

Co-authored-by: Michael Macias <[email protected]>
  • Loading branch information
holtgrewe and zaeleus authored Oct 23, 2023
1 parent f08447c commit e8ff8c9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
9 changes: 9 additions & 0 deletions noodles-vcf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

### Added

* vcf/async: Add common methods to access the underlying I/O:
`AsyncReader::get_ref`, `AsyncReader::get_mut`, `AsyncReader::into_inner`,
`AsyncWriter::get_ref`, `AsyncWriter::get_mut`, and
`AsyncWriter::into_inner`.

## 0.42.0 - 2023-10-19

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

/// Returns a reference to the underlying reader.
///
/// # Examples
///
/// ```
/// use noodles_vcf as vcf;
/// let data = [];
/// let reader = vcf::AsyncReader::new(&data[..]);
/// assert!(reader.get_ref().is_empty());
/// ```
pub fn get_ref(&self) -> &R {
&self.inner
}

/// Returns a mutable reference to the underlying reader.
///
/// # Examples
///
/// ```
/// use noodles_vcf as vcf;
/// let data = [];
/// let mut reader = vcf::AsyncReader::new(&data[..]);
/// assert!(reader.get_mut().is_empty());
/// ```
pub fn get_mut(&mut self) -> &mut R {
&mut self.inner
}

/// Returns the underlying reader.
///
/// # Examples
///
/// ```
/// use noodles_vcf as vcf;
/// let data = [];
/// let reader = vcf::AsyncReader::new(&data[..]);
/// assert!(reader.into_inner().is_empty());
/// ```
pub fn into_inner(self) -> R {
self.inner
}

/// Reads the VCF header.
///
/// This reads all header lines prefixed with a `#` (number sign), which includes the header
Expand Down
39 changes: 39 additions & 0 deletions noodles-vcf/src/async/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,45 @@ where
Self { inner }
}

/// Returns a reference to the underlying writer.
///
/// # Examples
///
/// ```
/// use noodles_vcf as vcf;
/// let writer = vcf::AsyncWriter::new(Vec::new());
/// assert!(writer.get_ref().is_empty());
/// ```
pub fn get_ref(&self) -> &W {
&self.inner
}

/// Returns a mutable reference to the underlying writer.
///
/// # Examples
///
/// ```
/// use noodles_vcf as vcf;
/// let mut writer = vcf::AsyncWriter::new(Vec::new());
/// assert!(writer.get_mut().is_empty());
/// ```
pub fn get_mut(&mut self) -> &mut W {
&mut self.inner
}

/// Returns the underlying writer.
///
/// # Examples
///
/// ```
/// use noodles_vcf as vcf;
/// let writer = vcf::AsyncWriter::new(Vec::new());
/// assert!(writer.into_inner().is_empty());
/// ```
pub fn into_inner(self) -> W {
self.inner
}

/// Writes a VCF header.
///
/// # Examples
Expand Down

0 comments on commit e8ff8c9

Please sign in to comment.