Skip to content

Commit

Permalink
fasta/io/writer/builder: Add build from path
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Oct 17, 2024
1 parent 14090bc commit 4937b24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions noodles-fasta/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* fasta/async/io: Add async writer (`fasta::r#async::io::Writer`).

* fasta/io/writer/builder: Add build from path (`Builder::build_from_path`).

### Deprecated

* fasta: Deprecate async re-export (`AsyncReader`).
Expand Down
22 changes: 21 additions & 1 deletion noodles-fasta/src/io/writer/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::io::Write;
use std::{
fs::File,
io::{self, Write},
path::Path,
};

use super::Writer;

Expand All @@ -25,6 +29,22 @@ impl Builder {
self
}

/// Builds a FASTA writer from a path.
///
/// # Examples
///
/// ```no_run
/// use noodles_fasta as fasta;
/// let writer = fasta::io::writer::Builder::default().build_from_path("out.fa")?;
/// # Ok::<_, std::io::Error>(())
/// ```
pub fn build_from_path<P>(self, dst: P) -> io::Result<Writer<File>>
where
P: AsRef<Path>,
{
File::create(dst).map(|file| self.build_from_writer(file))
}

/// Builds a FASTA writer from a writer.
///
/// # Examples
Expand Down

0 comments on commit 4937b24

Please sign in to comment.