From e601e3d3251123d5b7c635e5bdc4490050c5d69f Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Tue, 27 Aug 2024 07:29:37 -0500 Subject: [PATCH] cram/io/writer/builder: Rename Builder::build_with_writer to Builder::build_from_writer Closes #295. --- noodles-cram/CHANGELOG.md | 11 +++++++---- noodles-cram/examples/cram_write.rs | 2 +- noodles-cram/examples/cram_write_async.rs | 2 +- noodles-cram/src/async/io/writer.rs | 2 +- noodles-cram/src/async/io/writer/builder.rs | 15 ++++++++++++--- noodles-cram/src/io/writer.rs | 2 +- noodles-cram/src/io/writer/builder.rs | 15 ++++++++++++--- .../src/alignment/async/io/writer/builder.rs | 2 +- noodles-util/src/alignment/io/writer/builder.rs | 2 +- 9 files changed, 37 insertions(+), 16 deletions(-) diff --git a/noodles-cram/CHANGELOG.md b/noodles-cram/CHANGELOG.md index 040c68093..17f69e14c 100644 --- a/noodles-cram/CHANGELOG.md +++ b/noodles-cram/CHANGELOG.md @@ -18,16 +18,19 @@ ### Changed - * cram/io/writer/builder: Rename `Builder::build_with_path` to - `Builder::build_from_path` ([#295]). + * cram/io/writer/builder: Rename `Builder::build_with_path` and + `Builder::build_with_writer` to `Builder::build_from_path` and + `Builder::build_from_writer`, respectively ([#295]). [#295]: https://github.com/zaeleus/noodles/issues/295 ### Deprecated - * cram/io/writer/builder: Deprecate `Builder::build_with_path`. + * cram/io/writer/builder: Deprecate `Builder::build_with_path` and + `Builder::build_with_writer`. - Use `Builder::build_from_path` instead. + Use `Builder::build_from_path` and `Builder::build_from_writer`, + respectively, instead. ## 0.67.0 - 2024-08-04 diff --git a/noodles-cram/examples/cram_write.rs b/noodles-cram/examples/cram_write.rs index 3f6e48495..40c81020f 100644 --- a/noodles-cram/examples/cram_write.rs +++ b/noodles-cram/examples/cram_write.rs @@ -71,7 +71,7 @@ fn main() -> Result<(), Box> { let repository = fasta::Repository::new(reference_sequences); let mut writer = cram::io::writer::Builder::default() .set_reference_sequence_repository(repository) - .build_with_writer(stdout); + .build_from_writer(stdout); writer.write_header(&header)?; diff --git a/noodles-cram/examples/cram_write_async.rs b/noodles-cram/examples/cram_write_async.rs index 3d9b05a6b..40f52fe3b 100644 --- a/noodles-cram/examples/cram_write_async.rs +++ b/noodles-cram/examples/cram_write_async.rs @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box> { let repository = fasta::Repository::new(reference_sequences); let mut writer = cram::r#async::io::writer::Builder::default() .set_reference_sequence_repository(repository) - .build_with_writer(io::stdout()); + .build_from_writer(io::stdout()); writer.write_file_definition().await?; writer.write_file_header(&header).await?; diff --git a/noodles-cram/src/async/io/writer.rs b/noodles-cram/src/async/io/writer.rs index 3689880c6..d60fa5cc0 100644 --- a/noodles-cram/src/async/io/writer.rs +++ b/noodles-cram/src/async/io/writer.rs @@ -42,7 +42,7 @@ where /// let writer = cram::r#async::io::Writer::new(io::sink()); /// ``` pub fn new(inner: W) -> Self { - Builder::default().build_with_writer(inner) + Builder::default().build_from_writer(inner) } /// Returns a reference to the underlying writer. diff --git a/noodles-cram/src/async/io/writer/builder.rs b/noodles-cram/src/async/io/writer/builder.rs index 6e794124e..22f088d6a 100644 --- a/noodles-cram/src/async/io/writer/builder.rs +++ b/noodles-cram/src/async/io/writer/builder.rs @@ -73,7 +73,7 @@ impl Builder { { File::create(dst) .await - .map(|file| self.build_with_writer(file)) + .map(|file| self.build_from_writer(file)) } /// Builds an async CRAM writer from a path. @@ -92,9 +92,9 @@ impl Builder { /// ``` /// use noodles_cram as cram; /// use tokio::io; - /// let writer = cram::r#async::io::writer::Builder::default().build_with_writer(io::sink()); + /// let writer = cram::r#async::io::writer::Builder::default().build_from_writer(io::sink()); /// ``` - pub fn build_with_writer(mut self, writer: W) -> Writer + pub fn build_from_writer(mut self, writer: W) -> Writer where W: AsyncWrite + Unpin, { @@ -112,4 +112,13 @@ impl Builder { record_counter: 0, } } + + /// Builds an async CRAM writer from a writer. + #[deprecated(since = "0.68.0", note = "Use `Builder::build_from_writer` instead.")] + pub fn build_with_writer(self, writer: W) -> Writer + where + W: AsyncWrite + Unpin, + { + self.build_from_writer(writer) + } } diff --git a/noodles-cram/src/io/writer.rs b/noodles-cram/src/io/writer.rs index df5a5402e..9f67f496d 100644 --- a/noodles-cram/src/io/writer.rs +++ b/noodles-cram/src/io/writer.rs @@ -68,7 +68,7 @@ where /// let writer = cram::io::Writer::new(Vec::new()); /// ``` pub fn new(inner: W) -> Self { - Builder::default().build_with_writer(inner) + Builder::default().build_from_writer(inner) } /// Returns a reference to the underlying writer. diff --git a/noodles-cram/src/io/writer/builder.rs b/noodles-cram/src/io/writer/builder.rs index b4ed2b9eb..3e1087b9a 100644 --- a/noodles-cram/src/io/writer/builder.rs +++ b/noodles-cram/src/io/writer/builder.rs @@ -104,7 +104,7 @@ impl Builder { where P: AsRef, { - File::create(dst).map(|file| self.build_with_writer(file)) + File::create(dst).map(|file| self.build_from_writer(file)) } /// Builds a CRAM writer from a path. @@ -122,9 +122,9 @@ impl Builder { /// /// ``` /// use noodles_cram::io::writer::Builder; - /// let writer = Builder::default().build_with_writer(Vec::new()); + /// let writer = Builder::default().build_from_writer(Vec::new()); /// ``` - pub fn build_with_writer(mut self, writer: W) -> Writer + pub fn build_from_writer(mut self, writer: W) -> Writer where W: Write, { @@ -140,6 +140,15 @@ impl Builder { record_counter: 0, } } + + /// Builds a CRAM writer from a writer. + #[deprecated(since = "0.68.0", note = "Use `Builder::build_from_writer` instead.")] + pub fn build_with_writer(self, writer: W) -> Writer + where + W: Write, + { + self.build_from_writer(writer) + } } pub fn uses_cram_3_1_codecs(block_content_encoder_map: &BlockContentEncoderMap) -> bool { diff --git a/noodles-util/src/alignment/async/io/writer/builder.rs b/noodles-util/src/alignment/async/io/writer/builder.rs index 278a75ca4..1f591cf51 100644 --- a/noodles-util/src/alignment/async/io/writer/builder.rs +++ b/noodles-util/src/alignment/async/io/writer/builder.rs @@ -171,7 +171,7 @@ impl Builder { let inner: Box = Box::new(writer); let inner = cram::r#async::io::writer::Builder::default() .set_reference_sequence_repository(self.reference_sequence_repository) - .build_with_writer(inner); + .build_from_writer(inner); Writer::Cram(inner) } (Format::Cram, Some(CompressionMethod::Bgzf)) => { diff --git a/noodles-util/src/alignment/io/writer/builder.rs b/noodles-util/src/alignment/io/writer/builder.rs index 314f1aba0..83ab6eb3b 100644 --- a/noodles-util/src/alignment/io/writer/builder.rs +++ b/noodles-util/src/alignment/io/writer/builder.rs @@ -172,7 +172,7 @@ impl Builder { cram::io::writer::Builder::default() .set_reference_sequence_repository(self.reference_sequence_repository) .set_block_content_encoder_map(self.block_content_encoder_map) - .build_with_writer(writer), + .build_from_writer(writer), ), (Format::Cram, Some(CompressionMethod::Bgzf)) => { return Err(io::Error::new(