Skip to content

Commit

Permalink
docs: Add example for fusio_opendal (#92)
Browse files Browse the repository at this point in the history
* docs: Add example for fusio_opendal

Signed-off-by: Xuanwo <[email protected]>

* chore: format

---------

Signed-off-by: Xuanwo <[email protected]>
Co-authored-by: Gwo Tzu-Hsing <[email protected]>
  • Loading branch information
Xuanwo and ethe authored Nov 2, 2024
1 parent db30559 commit 77b3b1a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
1 change: 1 addition & 0 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod fs;
mod multi_runtime;
mod object;
mod opendal;
mod s3;

use fusio::{Error, IoBuf, IoBufMut, Read, Write};
Expand Down
22 changes: 22 additions & 0 deletions examples/src/opendal.rs
Original file line number Diff line number Diff line change
@@ -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<dyn DynFs> = Arc::new(OpendalFs::from(op));

let mut file: Box<dyn DynFile> = 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");
}

0 comments on commit 77b3b1a

Please sign in to comment.