Expand description
Fusio is a library that provides a unified IO interface for different IO backends.
§Example
use fusio::{Error, IoBuf, IoBufMut, Read, Write};
async fn write_without_runtime_awareness<F, B, BM>(
file: &mut F,
write_buf: B,
read_buf: BM,
) -> (Result<(), Error>, B, BM)
where
F: Read + Write,
B: IoBuf,
BM: IoBufMut,
{
let (result, write_buf) = file.write_all(write_buf).await;
if result.is_err() {
return (result, write_buf, read_buf);
}
file.close().await.unwrap();
let (result, read_buf) = file.read_exact_at(read_buf, 0).await;
if result.is_err() {
return (result.map(|_| ()), write_buf, read_buf);
}
(Ok(()), write_buf, read_buf)
}
#[tokio::main]
async fn main() {
#[cfg(feature = "tokio")]
{
use tokio::fs::File;
let mut file = File::open("foo.txt").await.unwrap();
let write_buf = "hello, world".as_bytes();
let mut read_buf = [0; 12];
let (result, _, read_buf) =
write_without_runtime_awareness(&mut file, write_buf, &mut read_buf[..]).await;
result.unwrap();
assert_eq!(&read_buf, b"hello, world");
}
}Re-exports§
pub use buf::IoBuf;pub use buf::IoBufMut;pub use dynamic::fs::DynFs;pub use dynamic::DynRead;pub use dynamic::DynWrite;pub use impls::*;
Modules§
- Buffer abstraction for I/O operations.
- This module contains the
Fstrait, which is used to abstract file system operations across different file systems. - Implementations of the traits in the
fusiocrate. - A path abstraction that can be used to represent paths in a cloud-agnostic way.
Enums§
Traits§
- Considering lots of runtimes does not require
std::marker::Sendforstd::future::Futureandfutures_core::stream::Stream, we provide a trait to represent the future or stream that may not requirestd::marker::Send. Users could switch the featureno-sendat compile-time to disable thestd::marker::Sendbound forstd::future::Futureandfutures_core::stream::Stream. - Same as
MaybeSend, but forstd::marker::Sync. - The core trait for reading data, it is similar to
std::io::Read, but it takes the ownership of the buffer, because completion-based IO requires the buffer to be pinned and should be safe to cancellation. - The core trait for writing data, it is similar to
std::io::Write, but it takes the ownership of the buffer, because completion-based IO requires the buffer to be pinned and should be safe to cancellation.