From 77b3b1aadf197e307bb2c7b38983bbbce5d5426f Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Sat, 2 Nov 2024 14:13:22 +0800 Subject: [PATCH] docs: Add example for fusio_opendal (#92) * docs: Add example for fusio_opendal Signed-off-by: Xuanwo * chore: format --------- Signed-off-by: Xuanwo Co-authored-by: Gwo Tzu-Hsing --- examples/Cargo.toml | 4 ++++ examples/src/lib.rs | 1 + examples/src/opendal.rs | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 examples/src/opendal.rs diff --git a/examples/Cargo.toml b/examples/Cargo.toml index acaf97e..3695f16 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -12,5 +12,9 @@ tokio = ["dep:tokio", "fusio/tokio"] [dependencies] fusio = { path = "../fusio" } +fusio-opendal = { path = "../fusio-opendal" } monoio = { version = "0.2", optional = true } +opendal = { version = "0.50.1", default-features = false, features = [ + "services-memory", +] } tokio = { version = "1.0", features = ["full"], optional = true } diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 8f9da44..c3e7a55 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -1,6 +1,7 @@ mod fs; mod multi_runtime; mod object; +mod opendal; mod s3; use fusio::{Error, IoBuf, IoBufMut, Read, Write}; diff --git a/examples/src/opendal.rs b/examples/src/opendal.rs new file mode 100644 index 0000000..eaedfc0 --- /dev/null +++ b/examples/src/opendal.rs @@ -0,0 +1,22 @@ +use std::sync::Arc; + +use fusio::{dynamic::DynFile, DynFs}; +use fusio_opendal::OpendalFs; +use opendal::{services::Memory, Operator}; + +#[allow(unused)] +async fn use_opendalfs() { + let op = Operator::new(Memory::default()).unwrap().finish(); + let fs: Arc = Arc::new(OpendalFs::from(op)); + + let mut file: Box = Box::new(fs.open(&"foo.txt".into()).await.unwrap()); + + let write_buf = "hello, world".as_bytes(); + let mut read_buf = [0; 12]; + + let (result, _, read_buf) = + crate::write_without_runtime_awareness(&mut file, write_buf, &mut read_buf[..]).await; + result.unwrap(); + + assert_eq!(&read_buf, b"hello, world"); +}