Crate fusio

Source
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§

Modules§

  • Buffer abstraction for I/O operations.
  • Dyn compatible(object safety) version of Read, Write and others.
  • This module contains the Fs trait, which is used to abstract file system operations across different file systems.
  • Implementations of the traits in the fusio crate.
  • A path abstraction that can be used to represent paths in a cloud-agnostic way.

Enums§

Traits§