diff --git a/README.md b/README.md
index e9cbe0f..2730c14 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,16 @@
# Fusio
-`fusio` provides [Read](https://github.com/tonbo-io/fusio/blob/main/fusio/src/lib.rs#L63) and [Write](https://github.com/tonbo-io/fusio/blob/main/fusio/src/lib.rs#L50) traits to operate on multiple storage backends (e.g., local disk, Amazon S3) across various asynchronous runtimes—both poll-based ([tokio](https://github.com/tokio-rs/tokio)) and completion-based ([tokio-uring](https://github.com/tokio-rs/tokio-uring), [monoio](https://github.com/bytedance/monoio))—with:
+
+
+
+
+
+
+
+
+
+
+`fusio` provides [Read](https://docs.rs/fusio/latest/fusio/trait.Read.html) and [Write](https://docs.rs/fusio/latest/fusio/trait.Write.html) traits to operate on multiple storage backends (e.g., local disk, Amazon S3) across various asynchronous runtimes—both poll-based ([tokio](https://github.com/tokio-rs/tokio)) and completion-based ([tokio-uring](https://github.com/tokio-rs/tokio-uring), [monoio](https://github.com/bytedance/monoio))—with:
- lean: binary size is at least 14× smaller than others.
- minimal-cost abstraction: compared to bare storage backends, trait definitions allow dispatching file operations without extra overhead.
- extensible: exposes traits to support implementing storage backends as third-party crates.
diff --git a/fusio/src/buf/mod.rs b/fusio/src/buf/mod.rs
index 58bb160..6c91352 100644
--- a/fusio/src/buf/mod.rs
+++ b/fusio/src/buf/mod.rs
@@ -1,3 +1,5 @@
+//! Buffer abstraction for I/O operations.
+
mod slice;
use std::ops::{Bound, RangeBounds};
@@ -6,15 +8,20 @@ pub use slice::*;
use crate::MaybeSend;
-/// # Safety
-/// Completion-based I/O operations require the buffer to be pinned.
#[cfg(not(feature = "completion-based"))]
-pub unsafe trait MaybeOwned {}
+pub unsafe trait MaybeOwned {
+ //! A trait for determining whether the buffer is owned or borrowed.
+ //! Poll-based I/O operations require the buffer to be borrowed, while completion-based I/O
+ //! operations require the buffer to be owned. This trait provides a way to abstract over
+ //! the ownership of the buffer. Users could switch between poll-based and completion-based
+ //! I/O operations at compile-time by enabling or disabling the `completion-based` feature.
+ //!
+ //! # Safety
+ //! Do not implement this trait manually.
+}
#[cfg(not(feature = "completion-based"))]
unsafe impl MaybeOwned for T {}
-/// # Safety
-/// Completion-based I/O operations require the buffer to be pinned.
#[cfg(feature = "completion-based")]
pub unsafe trait MaybeOwned: 'static {}
@@ -22,6 +29,13 @@ pub unsafe trait MaybeOwned: 'static {}
unsafe impl MaybeOwned for T {}
pub trait IoBuf: Unpin + Sized + MaybeOwned + MaybeSend {
+ //! A poll-based I/O and completion-based I/O buffer compatible buffer.
+ //! The [`IoBuf`] trait is implemented by buffer types that can be used with [`crate::Read`].
+ //! Fusio has already implemented this trait for common buffer types
+ //! like `Vec`, `&[u8]`, `&mut [u8]`, `bytes::Bytes`, `bytes::BytesMut`, every buffer type
+ //! may be not be able to be used in all async runtimes, fusio provides compile-time safety to
+ //! ensure which buffer types are compatible with the async runtime.
+
fn as_ptr(&self) -> *const u8;
fn bytes_init(&self) -> usize;
@@ -60,6 +74,8 @@ pub trait IoBuf: Unpin + Sized + MaybeOwned + MaybeSend {
}
pub trait IoBufMut: IoBuf {
+ //! Mutable version of [`IoBuf`] which is used with [`crate::Write`].
+
fn as_mut_ptr(&mut self) -> *mut u8;
fn as_slice_mut(&mut self) -> &mut [u8] {
diff --git a/fusio/src/dynamic/mod.rs b/fusio/src/dynamic/mod.rs
index 0d7a935..6b4e9c9 100644
--- a/fusio/src/dynamic/mod.rs
+++ b/fusio/src/dynamic/mod.rs
@@ -1,3 +1,5 @@
+//! Dyn compatible(object safety) version of [`Read`], [`Write`] and others.
+
#[cfg(feature = "fs")]
pub mod fs;
@@ -16,6 +18,11 @@ pub trait MaybeSendFuture: Future + MaybeSend {}
impl MaybeSendFuture for F where F: Future + MaybeSend {}
pub trait DynWrite: MaybeSend {
+ //! Dyn compatible(object safety) version of [`Write`].
+ //! All implementations of [`Write`] has already implemented this trait.
+ //! Also, all implementations of [`DynWrite`] has already implemented [`Write`].
+ //! User should not use this trait directly.
+
fn write_all(
&mut self,
buf: Slice,
@@ -44,6 +51,9 @@ impl DynWrite for W {
}
pub trait DynRead: MaybeSend + MaybeSync {
+ //! Dyn compatible(object safety) version of [`Read`].
+ //! Same as [`DynWrite`].
+
fn read_exact_at(
&mut self,
buf: SliceMut,
diff --git a/fusio/src/fs/mod.rs b/fusio/src/fs/mod.rs
index 64a111b..8105bab 100644
--- a/fusio/src/fs/mod.rs
+++ b/fusio/src/fs/mod.rs
@@ -1,3 +1,6 @@
+//! This module contains the `Fs` trait, which is used to abstract file system operations across
+//! different file systems.
+
mod options;
use std::future::Future;
@@ -14,6 +17,8 @@ pub struct FileMeta {
}
pub trait Fs: MaybeSend + MaybeSync {
+ //! This trait is used to abstract file system operations across different file systems.
+
type File: Read + Write + MaybeSend + 'static;
fn open(&self, path: &Path) -> impl Future