From 9d0f71557cbee0f3d475d4cd735fa8a6337f6fd4 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 16 Oct 2024 11:15:02 +0800 Subject: [PATCH] feat: Add OpenDAL Compat (#5185) --- .github/workflows/ci_integration_compat.yml | 51 +++ .github/workflows/docs.yml | 30 ++ .github/workflows/release_rust.yml | 1 + core/src/types/operator/operator.rs | 9 +- integrations/compat/.gitignore | 1 + integrations/compat/Cargo.toml | 36 ++ integrations/compat/README.md | 61 +++ integrations/compat/src/lib.rs | 43 ++ integrations/compat/src/v0_50_to_v0_49.rs | 461 ++++++++++++++++++++ 9 files changed, 690 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci_integration_compat.yml create mode 100644 integrations/compat/.gitignore create mode 100644 integrations/compat/Cargo.toml create mode 100644 integrations/compat/README.md create mode 100644 integrations/compat/src/lib.rs create mode 100644 integrations/compat/src/v0_50_to_v0_49.rs diff --git a/.github/workflows/ci_integration_compat.yml b/.github/workflows/ci_integration_compat.yml new file mode 100644 index 000000000000..ec1f4b5b47e4 --- /dev/null +++ b/.github/workflows/ci_integration_compat.yml @@ -0,0 +1,51 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: Integration Compat CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + paths: + - "integrations/compat/**" + - "core/**" + - ".github/workflows/ci_integration_compat.yml" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +jobs: + check_clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: ./.github/actions/setup + + - name: Cargo clippy + working-directory: integrations/compat + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Cargo test + working-directory: integrations/compat + run: cargo test --all-features diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c741684a962d..374345037284 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -459,6 +459,29 @@ jobs: name: object-parquet-docs path: ./integrations/parquet/target/doc + build-opendal-compat-doc: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: ./.github/actions/setup + + - name: Setup Rust Nightly + run: | + rustup toolchain install ${{ env.RUST_DOC_TOOLCHAIN }} + + - name: Build opendal_compat doc + working-directory: "integrations/compat" + run: cargo +${{ env.RUST_DOC_TOOLCHAIN }} doc --lib --no-deps --all-features + + - name: Upload docs + uses: actions/upload-artifact@v3 + with: + name: opendal-compat-docs + path: ./integrations/compat/target/doc + build-website: runs-on: ubuntu-latest permissions: @@ -479,6 +502,7 @@ jobs: - build-unftp-sbe-opendal-doc - build-virtiofs-opendal-doc - build-parquet-opendal-doc + - build-opendal-compat-doc steps: - uses: actions/checkout@v4 @@ -559,6 +583,12 @@ jobs: name: object-store-opendal-docs path: ./website/static/docs/object-store-opendal + - name: Download opendal_compat docs + uses: actions/download-artifact@v3 + with: + name: opendal-compat-docs + path: ./website/static/docs/opendal_compat + - name: Download dav-server-opendalfs docs uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/release_rust.yml b/.github/workflows/release_rust.yml index a8d9921f0665..990374dd083e 100644 --- a/.github/workflows/release_rust.yml +++ b/.github/workflows/release_rust.yml @@ -41,6 +41,7 @@ jobs: # Order here is sensitive, as it will be used to determine the order of publishing package: - "core" + - "integrations/compat" - "integrations/object_store" - "integrations/parquet" - "integrations/dav-server" diff --git a/core/src/types/operator/operator.rs b/core/src/types/operator/operator.rs index 09b09a401dab..e2451a3ad270 100644 --- a/core/src/types/operator/operator.rs +++ b/core/src/types/operator/operator.rs @@ -69,11 +69,13 @@ pub struct Operator { /// # Operator basic API. impl Operator { - pub(crate) fn inner(&self) -> &Accessor { + /// Fetch the internal accessor. + pub fn inner(&self) -> &Accessor { &self.accessor } - pub(crate) fn from_inner(accessor: Accessor) -> Self { + /// Convert inner accessor into operator. + pub fn from_inner(accessor: Accessor) -> Self { let limit = accessor .info() .full_capability() @@ -86,7 +88,8 @@ impl Operator { } } - pub(crate) fn into_inner(self) -> Accessor { + /// Convert operator into inner accessor. + pub fn into_inner(self) -> Accessor { self.accessor } diff --git a/integrations/compat/.gitignore b/integrations/compat/.gitignore new file mode 100644 index 000000000000..03314f77b5aa --- /dev/null +++ b/integrations/compat/.gitignore @@ -0,0 +1 @@ +Cargo.lock diff --git a/integrations/compat/Cargo.toml b/integrations/compat/Cargo.toml new file mode 100644 index 000000000000..4fc457d9882c --- /dev/null +++ b/integrations/compat/Cargo.toml @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +[package] +description = "Apache OpenDAL Compat" +name = "opendal_compat" + +authors = ["Apache OpenDAL "] +edition = "2021" +homepage = "https://opendal.apache.org/" +license = "Apache-2.0" +repository = "https://github.com/apache/opendal" +rust-version = "1.75" +version = "1.0.0" + +[features] +v0_50_to_v0_49 = ["dep:opendal_v0_49", "dep:opendal_v0_50"] + +[dependencies] +async-trait = "0.1" +opendal_v0_49 = { package = "opendal", version = "0.49", optional = true } +opendal_v0_50 = { package = "opendal", version = "0.50", optional = true, path = "../../core" } diff --git a/integrations/compat/README.md b/integrations/compat/README.md new file mode 100644 index 000000000000..a2882ff79ba1 --- /dev/null +++ b/integrations/compat/README.md @@ -0,0 +1,61 @@ +# Apache OpenDALâ„¢ Compat integration + +[![Build Status]][actions] [![Latest Version]][crates.io] [![Crate Downloads]][crates.io] [![chat]][discord] + +[build status]: https://img.shields.io/github/actions/workflow/status/apache/opendal/ci_integration_compat.yml?branch=main +[actions]: https://github.com/apache/opendal/actions?query=branch%3Amain +[latest version]: https://img.shields.io/crates/v/opendal_compat.svg +[crates.io]: https://crates.io/crates/opendal_compat +[crate downloads]: https://img.shields.io/crates/d/opendal_compat.svg +[chat]: https://img.shields.io/discord/1081052318650339399 +[discord]: https://opendal.apache.org/discord + +`opendal-compat` provides compatibility functions for opendal. + +This crate can make it easier to resolve the compatibility issues between different versions of opendal. + +## Useful Links + +- Documentation: [release](https://docs.rs/opendal_compat/) | [dev](https://opendal.apache.org/docs/opendal_compat/opendal_compat/) + +## Examples + +Add the following dependencies to your `Cargo.toml` with correct version: + +```toml +[dependencies] +opendal_compat = { version = "1", features = ["v0_50_to_v0_49"] } +opendal = { version = "0.50.0" } +opendal_v0_49 = { package="opendal", version = "0.49" } +``` + +Convert `opendal::Operator` to old opendal `Operator`: + +```rust +use opendal_v0_50::Operator; +use opendal_v0_50::services::MemoryConfig; +use opendal_v0_50::Result; + +fn i_need_opendal_v0_49_op(op: opendal_v0_49::Operator) { + // do something with old opendal; +} + +fn main() -> Result<()> { + let v0_50_op = Operator::from_config(MemoryConfig::default())?.finish(); + let v0_49_op = opendal_compat::v0_50_to_v0_49(v0_50_op); + i_need_opendal_v0_49_op(v0_49_op); + Ok(()) +} +``` + +## Branding + +The first and most prominent mentions must use the full form: **Apache OpenDALâ„¢** of the name for any individual usage (webpage, handout, slides, etc.) Depending on the context and writing style, you should use the full form of the name sufficiently often to ensure that readers clearly understand the association of both the OpenDAL project and the OpenDAL software product to the ASF as the parent organization. + +For more details, see the [Apache Product Name Usage Guide](https://www.apache.org/foundation/marks/guide). + +## License and Trademarks + +Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 + +Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation. diff --git a/integrations/compat/src/lib.rs b/integrations/compat/src/lib.rs new file mode 100644 index 000000000000..018505fafaf7 --- /dev/null +++ b/integrations/compat/src/lib.rs @@ -0,0 +1,43 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! `opendal_compat` provides compatibility functions for opendal. +//! +//! OpenDAL is widely used across the entire big data ecosystem. Various projects may utilize +//! different versions of OpenDAL. This crate provides compatibility functions to assist users +//! in upgrading OpenDAL without altering their existing code, especially for projects that +//! accept OpenDAL Operators. +//! +//! Please note that `opendal_compat` only ensures that the code compiles and runs. However, +//! it does not guarantee that the code will function as expected. The underlying behavior of +//! OpenDAL may vary between versions, and the compatibility functions might not address all +//! changes. It is advisable to test the code thoroughly after upgrading OpenDAL. +//! +//! This project is organized by version. Each version has its own module hidden within a feature, +//! and each module contains only one function that converts from the latest version to the +//! previous version. +//! +//! Currently, `opendal_compat` supports the following versions: +//! +//! - [`v0_50_to_v0_49()`] +//! +//! Please refer to the specific function for more information. + +#[cfg(feature = "v0_50_to_v0_49")] +mod v0_50_to_v0_49; +#[cfg(feature = "v0_50_to_v0_49")] +pub use v0_50_to_v0_49::v0_50_to_v0_49; diff --git a/integrations/compat/src/v0_50_to_v0_49.rs b/integrations/compat/src/v0_50_to_v0_49.rs new file mode 100644 index 000000000000..d26bfff39266 --- /dev/null +++ b/integrations/compat/src/v0_50_to_v0_49.rs @@ -0,0 +1,461 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use opendal_v0_49::raw::{ + AccessorInfo, OpBatch, OpCopy, OpCreateDir, OpDelete, OpList, OpPresign, OpRead, OpRename, + OpStat, OpWrite, RpBatch, RpCopy, RpCreateDir, RpDelete, RpList, RpPresign, RpRead, RpRename, + RpStat, RpWrite, +}; +use opendal_v0_49::Buffer; +use std::fmt::{Debug, Formatter}; +use std::sync::Arc; + +/// Convert an opendal v0.50 `Operator` into an opendal v0.49 `Operator` for compatibility. +/// +/// ```rust +/// use opendal_v0_50::Operator; +/// use opendal_v0_50::services::MemoryConfig; +/// use opendal_v0_50::Result; +/// +/// fn i_need_opendal_v0_49_op(op: opendal_v0_49::Operator) { +/// // do something with old opendal; +/// } +/// +/// fn main() -> Result<()> { +/// let v0_50_op = Operator::from_config(MemoryConfig::default())?.finish(); +/// let v0_49_op = opendal_compat::v0_50_to_v0_49(v0_50_op); +/// i_need_opendal_v0_49_op(v0_49_op); +/// Ok(()) +/// } +/// ``` +pub fn v0_50_to_v0_49(v: opendal_v0_50::Operator) -> opendal_v0_49::Operator { + let acc = CompatAccessor(v.into_inner()); + opendal_v0_49::OperatorBuilder::new(acc).finish() +} + +struct CompatAccessor(A); + +impl Debug for CompatAccessor { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + +impl opendal_v0_49::raw::Access for CompatAccessor { + type Reader = CompatWrapper; + type Writer = CompatWrapper; + type Lister = CompatWrapper; + type BlockingReader = CompatWrapper; + type BlockingWriter = CompatWrapper; + type BlockingLister = CompatWrapper; + + fn info(&self) -> Arc { + convert::raw_oio_accessor_info_into(self.0.info()) + } + + async fn create_dir(&self, path: &str, _: OpCreateDir) -> opendal_v0_49::Result { + self.0 + .create_dir(path, opendal_v0_50::raw::OpCreateDir::new()) + .await + .map_err(convert::error_into)?; + Ok(RpCreateDir::default()) + } + + async fn stat(&self, path: &str, args: OpStat) -> opendal_v0_49::Result { + self.0 + .stat(path, convert::raw_op_stat_from(args)) + .await + .map(convert::raw_rp_stat_into) + .map_err(convert::error_into) + } + + async fn read( + &self, + path: &str, + args: OpRead, + ) -> opendal_v0_49::Result<(RpRead, Self::Reader)> { + let (rp, reader) = self + .0 + .read(path, convert::raw_op_read_from(args)) + .await + .map_err(convert::error_into)?; + Ok((convert::raw_rp_read_into(rp), CompatWrapper(reader))) + } + + async fn write( + &self, + path: &str, + args: OpWrite, + ) -> opendal_v0_49::Result<(RpWrite, Self::Writer)> { + let (rp, writer) = self + .0 + .write(path, convert::raw_op_write_from(args)) + .await + .map_err(convert::error_into)?; + Ok((convert::raw_rp_write_into(rp), CompatWrapper(writer))) + } + + async fn delete(&self, path: &str, args: OpDelete) -> opendal_v0_49::Result { + self.0 + .delete(path, convert::raw_op_delete_from(args)) + .await + .map(convert::raw_rp_delete_into) + .map_err(convert::error_into) + } + + async fn list( + &self, + path: &str, + args: OpList, + ) -> opendal_v0_49::Result<(RpList, Self::Lister)> { + let (rp, lister) = self + .0 + .list(path, convert::raw_op_list_from(args)) + .await + .map_err(convert::error_into)?; + Ok((convert::raw_rp_list_into(rp), CompatWrapper(lister))) + } + + async fn copy(&self, from: &str, to: &str, args: OpCopy) -> opendal_v0_49::Result { + self.0 + .copy(from, to, convert::raw_op_copy_from(args)) + .await + .map(convert::raw_rp_copy_into) + .map_err(convert::error_into) + } + + async fn rename( + &self, + from: &str, + to: &str, + args: OpRename, + ) -> opendal_v0_49::Result { + self.0 + .rename(from, to, convert::raw_op_rename_from(args)) + .await + .map(convert::raw_rp_rename_into) + .map_err(convert::error_into) + } + + async fn presign(&self, path: &str, args: OpPresign) -> opendal_v0_49::Result { + self.0 + .presign(path, convert::raw_op_presign_from(args)) + .await + .map(convert::raw_rp_presign_into) + .map_err(convert::error_into) + } + + async fn batch(&self, args: OpBatch) -> opendal_v0_49::Result { + self.0 + .batch(convert::raw_op_batch_from(args)) + .await + .map(convert::raw_rp_batch_into) + .map_err(convert::error_into) + } + + fn blocking_create_dir( + &self, + path: &str, + _: OpCreateDir, + ) -> opendal_v0_49::Result { + self.0 + .blocking_create_dir(path, opendal_v0_50::raw::OpCreateDir::new()) + .map_err(convert::error_into)?; + Ok(RpCreateDir::default()) + } + + fn blocking_stat(&self, path: &str, args: OpStat) -> opendal_v0_49::Result { + self.0 + .blocking_stat(path, convert::raw_op_stat_from(args)) + .map(convert::raw_rp_stat_into) + .map_err(convert::error_into) + } + + fn blocking_read( + &self, + path: &str, + args: OpRead, + ) -> opendal_v0_49::Result<(RpRead, Self::BlockingReader)> { + let (rp, reader) = self + .0 + .blocking_read(path, convert::raw_op_read_from(args)) + .map_err(convert::error_into)?; + Ok((convert::raw_rp_read_into(rp), CompatWrapper(reader))) + } + + fn blocking_write( + &self, + path: &str, + args: OpWrite, + ) -> opendal_v0_49::Result<(RpWrite, Self::BlockingWriter)> { + let (rp, writer) = self + .0 + .blocking_write(path, convert::raw_op_write_from(args)) + .map_err(convert::error_into)?; + Ok((convert::raw_rp_write_into(rp), CompatWrapper(writer))) + } + + fn blocking_delete(&self, path: &str, args: OpDelete) -> opendal_v0_49::Result { + self.0 + .blocking_delete(path, convert::raw_op_delete_from(args)) + .map(convert::raw_rp_delete_into) + .map_err(convert::error_into) + } + + fn blocking_list( + &self, + path: &str, + args: OpList, + ) -> opendal_v0_49::Result<(RpList, Self::BlockingLister)> { + let (rp, lister) = self + .0 + .blocking_list(path, convert::raw_op_list_from(args)) + .map_err(convert::error_into)?; + Ok((convert::raw_rp_list_into(rp), CompatWrapper(lister))) + } + + fn blocking_copy(&self, from: &str, to: &str, args: OpCopy) -> opendal_v0_49::Result { + self.0 + .blocking_copy(from, to, convert::raw_op_copy_from(args)) + .map(convert::raw_rp_copy_into) + .map_err(convert::error_into) + } + + fn blocking_rename( + &self, + from: &str, + to: &str, + args: OpRename, + ) -> opendal_v0_49::Result { + self.0 + .blocking_rename(from, to, convert::raw_op_rename_from(args)) + .map(convert::raw_rp_rename_into) + .map_err(convert::error_into) + } +} + +struct CompatWrapper(I); + +impl opendal_v0_49::raw::oio::Read for CompatWrapper { + async fn read(&mut self) -> opendal_v0_49::Result { + self.0 + .read() + .await + .map(convert::buffer_into) + .map_err(convert::error_into) + } +} + +impl opendal_v0_49::raw::oio::Write for CompatWrapper { + async fn write(&mut self, buf: Buffer) -> opendal_v0_49::Result<()> { + self.0 + .write(convert::buffer_from(buf)) + .await + .map_err(convert::error_into) + } + + async fn close(&mut self) -> opendal_v0_49::Result<()> { + self.0.close().await.map_err(convert::error_into) + } + + async fn abort(&mut self) -> opendal_v0_49::Result<()> { + self.0.abort().await.map_err(convert::error_into) + } +} + +impl opendal_v0_49::raw::oio::List for CompatWrapper { + async fn next(&mut self) -> opendal_v0_49::Result> { + self.0 + .next() + .await + .map(|v| v.map(convert::raw_oio_entry_into)) + .map_err(convert::error_into) + } +} + +impl opendal_v0_49::raw::oio::BlockingRead + for CompatWrapper +{ + fn read(&mut self) -> opendal_v0_49::Result { + self.0 + .read() + .map(convert::buffer_into) + .map_err(convert::error_into) + } +} + +impl opendal_v0_49::raw::oio::BlockingWrite + for CompatWrapper +{ + fn write(&mut self, buf: Buffer) -> opendal_v0_49::Result<()> { + self.0 + .write(convert::buffer_from(buf)) + .map_err(convert::error_into) + } + + fn close(&mut self) -> opendal_v0_49::Result<()> { + self.0.close().map_err(convert::error_into) + } +} + +impl opendal_v0_49::raw::oio::BlockingList + for CompatWrapper +{ + fn next(&mut self) -> opendal_v0_49::Result> { + self.0 + .next() + .map(|v| v.map(convert::raw_oio_entry_into)) + .map_err(convert::error_into) + } +} + +/// The `convert` module facilitates the conversion between opendal versions v0.50 and v0.49. +/// +/// # Notes +/// +/// We intentionally implemented all those conversion functions by hand. Since this is a +/// compatibility crate and opendal v0.49 will not receive updates, maintenance concerns are +/// minimal. By handling them manually, we can avoid the overhead associated with maintaining +/// a procedural macro. +/// +/// # Safety +/// +/// All types converted here are plain data types or depend on other `v1.0` crates such as `bytes` +/// or `anyhow`. This ensures that they are the same types, merely presented under different +/// versions of opendal. +/// +/// `transmute` also perform compile time checks to detect any type size mismatch like `OpWrite` +/// in which we added a new field since v0.50. +mod convert { + use std::mem::transmute; + use std::sync::Arc; + + pub fn error_into(e: opendal_v0_50::Error) -> opendal_v0_49::Error { + unsafe { transmute(e) } + } + + pub fn buffer_from(b: opendal_v0_49::Buffer) -> opendal_v0_50::Buffer { + unsafe { transmute(b) } + } + + pub fn buffer_into(b: opendal_v0_50::Buffer) -> opendal_v0_49::Buffer { + unsafe { transmute(b) } + } + + pub fn raw_oio_accessor_info_into( + e: Arc, + ) -> Arc { + unsafe { transmute(e) } + } + + pub fn raw_oio_entry_into(e: opendal_v0_50::raw::oio::Entry) -> opendal_v0_49::raw::oio::Entry { + unsafe { transmute(e) } + } + + pub fn raw_op_stat_from(e: opendal_v0_49::raw::OpStat) -> opendal_v0_50::raw::OpStat { + unsafe { transmute(e) } + } + + pub fn raw_rp_stat_into(e: opendal_v0_50::raw::RpStat) -> opendal_v0_49::raw::RpStat { + unsafe { transmute(e) } + } + + pub fn raw_op_read_from(e: opendal_v0_49::raw::OpRead) -> opendal_v0_50::raw::OpRead { + unsafe { transmute(e) } + } + + pub fn raw_rp_read_into(e: opendal_v0_50::raw::RpRead) -> opendal_v0_49::raw::RpRead { + unsafe { transmute(e) } + } + + pub fn raw_op_write_from(e: opendal_v0_49::raw::OpWrite) -> opendal_v0_50::raw::OpWrite { + let mut op = opendal_v0_50::raw::OpWrite::new() + .with_append(e.append()) + .with_concurrent(e.concurrent()); + + if let Some(v) = e.cache_control() { + op = op.with_cache_control(v); + } + + if let Some(v) = e.content_type() { + op = op.with_content_type(v); + } + + if let Some(v) = e.content_disposition() { + op = op.with_content_disposition(v); + } + + if let Some(v) = e.user_metadata() { + op = op.with_user_metadata(v.clone()); + } + + // We didn't implement `executor` field for `OpWrite`. + op + } + + pub fn raw_rp_write_into(e: opendal_v0_50::raw::RpWrite) -> opendal_v0_49::raw::RpWrite { + unsafe { transmute(e) } + } + + pub fn raw_op_delete_from(e: opendal_v0_49::raw::OpDelete) -> opendal_v0_50::raw::OpDelete { + unsafe { transmute(e) } + } + + pub fn raw_rp_delete_into(e: opendal_v0_50::raw::RpDelete) -> opendal_v0_49::raw::RpDelete { + unsafe { transmute(e) } + } + + pub fn raw_op_list_from(e: opendal_v0_49::raw::OpList) -> opendal_v0_50::raw::OpList { + unsafe { transmute(e) } + } + + pub fn raw_rp_list_into(e: opendal_v0_50::raw::RpList) -> opendal_v0_49::raw::RpList { + unsafe { transmute(e) } + } + + pub fn raw_op_copy_from(e: opendal_v0_49::raw::OpCopy) -> opendal_v0_50::raw::OpCopy { + unsafe { transmute(e) } + } + + pub fn raw_rp_copy_into(e: opendal_v0_50::raw::RpCopy) -> opendal_v0_49::raw::RpCopy { + unsafe { transmute(e) } + } + + pub fn raw_op_rename_from(e: opendal_v0_49::raw::OpRename) -> opendal_v0_50::raw::OpRename { + unsafe { transmute(e) } + } + + pub fn raw_rp_rename_into(e: opendal_v0_50::raw::RpRename) -> opendal_v0_49::raw::RpRename { + unsafe { transmute(e) } + } + + pub fn raw_op_presign_from(e: opendal_v0_49::raw::OpPresign) -> opendal_v0_50::raw::OpPresign { + unsafe { transmute(e) } + } + + pub fn raw_rp_presign_into(e: opendal_v0_50::raw::RpPresign) -> opendal_v0_49::raw::RpPresign { + unsafe { transmute(e) } + } + + pub fn raw_op_batch_from(e: opendal_v0_49::raw::OpBatch) -> opendal_v0_50::raw::OpBatch { + unsafe { transmute(e) } + } + + pub fn raw_rp_batch_into(e: opendal_v0_50::raw::RpBatch) -> opendal_v0_49::raw::RpBatch { + unsafe { transmute(e) } + } +}