Skip to content

Commit

Permalink
fasta/io/writer: Add additional methods to get the underlying writer
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Aug 3, 2024
1 parent e7dee1d commit 90f71c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
7 changes: 7 additions & 0 deletions noodles-fasta/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Added

* fasta/io/writer: Add additional methods to get the underlying writer
(`Writer::get_mut` and `Writer::into_inner`).

## 0.41.0 - 2024-07-14

### Added
Expand Down
55 changes: 43 additions & 12 deletions noodles-fasta/src/io/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,64 @@ pub struct Writer<W> {
line_base_count: usize,
}

impl<W> Writer<W>
where
W: Write,
{
/// Creates a FASTA writer.
impl<W> Writer<W> {
/// Returns a reference to the underlying writer.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_fasta as fasta;
/// let writer = fasta::io::Writer::new(Vec::new());
/// let writer = fasta::io::Writer::new(io::sink());
/// let _inner = writer.get_ref();
/// ```
pub fn new(inner: W) -> Self {
Builder::default().build_with_writer(inner)
pub fn get_ref(&self) -> &W {
&self.inner
}

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

/// Unwraps and returns the underlying writer.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_fasta as fasta;
/// let writer = fasta::io::Writer::new(io::sink());
/// let _inner = writer.into_inner();
/// ```
pub fn into_inner(self) -> W {
self.inner
}
}

impl<W> Writer<W>
where
W: Write,
{
/// Creates a FASTA writer.
///
/// # Examples
///
/// ```
/// use noodles_fasta as fasta;
/// let writer = fasta::io::Writer::new(Vec::new());
/// assert!(writer.get_ref().is_empty());
/// ```
pub fn get_ref(&self) -> &W {
&self.inner
pub fn new(inner: W) -> Self {
Builder::default().build_with_writer(inner)
}

/// Writes a FASTA record.
Expand Down

0 comments on commit 90f71c6

Please sign in to comment.