This is an automated email from the ASF dual-hosted git repository. xuanwo pushed a commit to branch refactor-write in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 54df6d92cb8e93e77ed46f8ba48266fff28788ff Author: Xuanwo <[email protected]> AuthorDate: Thu Sep 7 23:53:37 2023 +0800 Don't change public API Signed-off-by: Xuanwo <[email protected]> --- core/src/types/operator/operator.rs | 8 ++++---- core/src/types/writer.rs | 3 ++- core/tests/behavior/write.rs | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/types/operator/operator.rs b/core/src/types/operator/operator.rs index b51c2bc60..1c8c6cd12 100644 --- a/core/src/types/operator/operator.rs +++ b/core/src/types/operator/operator.rs @@ -622,8 +622,8 @@ impl Operator { /// # #[tokio::main] /// # async fn test(op: Operator) -> Result<()> { /// let mut w = op.writer("path/to/file").await?; - /// w.write(vec![0; 4096]).await?; - /// w.write(vec![1; 4096]).await?; + /// w.write(&vec![0; 4096]).await?; + /// w.write(&vec![1; 4096]).await?; /// w.close().await?; /// # Ok(()) /// # } @@ -651,8 +651,8 @@ impl Operator { /// .writer_with("path/to/file") /// .content_type("application/octet-stream") /// .await?; - /// w.write(vec![0; 4096]).await?; - /// w.write(vec![1; 4096]).await?; + /// w.write(&vec![0; 4096]).await?; + /// w.write(&vec![1; 4096]).await?; /// w.close().await?; /// # Ok(()) /// # } diff --git a/core/src/types/writer.rs b/core/src/types/writer.rs index 6714d8017..40d862701 100644 --- a/core/src/types/writer.rs +++ b/core/src/types/writer.rs @@ -80,7 +80,7 @@ impl Writer { } /// Write into inner writer. - pub async fn write(&mut self, mut bs: impl Buf) -> Result<()> { + pub async fn write(&mut self, bs: impl Into<Bytes>) -> Result<()> { let w = if let State::Idle(Some(w)) = &mut self.state { w } else { @@ -90,6 +90,7 @@ impl Writer { ); }; + let mut bs = bs.into(); while bs.remaining() > 0 { let n = w.write(&bs).await?; bs.advance(n); diff --git a/core/tests/behavior/write.rs b/core/tests/behavior/write.rs index f37f4a767..10c9e8c1a 100644 --- a/core/tests/behavior/write.rs +++ b/core/tests/behavior/write.rs @@ -994,7 +994,7 @@ pub async fn test_writer_abort(op: Operator) -> Result<()> { } }; - if let Err(e) = writer.write(content.as_slice()).await { + if let Err(e) = writer.write(content).await { assert_eq!(e.kind(), ErrorKind::Unsupported); return Ok(()); } @@ -1120,8 +1120,8 @@ pub async fn test_writer_write(op: Operator) -> Result<()> { let content_b = gen_fixed_bytes(size); let mut w = op.writer(&path).await?; - w.write(content_a.as_slice()).await?; - w.write(content_b.as_slice()).await?; + w.write(content_a.clone()).await?; + w.write(content_b.clone()).await?; w.close().await?; let meta = op.stat(&path).await.expect("stat must succeed");
