-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add example for fusio_opendal (#92)
* 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
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |