mp4forge/async_io.rs
1//! Tokio-based async I/O traits for the library-side async surface.
2//!
3//! The existing sync APIs remain the default path in `mp4forge`. The first async rollout is
4//! intentionally limited to seekable library readers and writers such as Tokio file handles or
5//! in-memory buffers. Later queue-backed follow-ons can also use the forward-only async reader
6//! and writer aliases in this module when a surface can operate progressively without seeks. The
7//! CLI continues to use the sync surface.
8
9/// Tokio async read trait used by the library-side async surface.
10pub use tokio::io::AsyncRead;
11/// Tokio async seek trait used by the library-side async surface.
12pub use tokio::io::AsyncSeek;
13/// Tokio async write trait used by the library-side async surface.
14pub use tokio::io::AsyncWrite;
15
16/// Async reader alias for forward-only library inputs.
17///
18/// Queue-backed progressive flows can use this bound when they only need incremental reads and do
19/// not require random-access seeks. The alias still requires `Send` so callers can move
20/// independent I/O jobs onto Tokio worker threads safely.
21pub trait AsyncReadForward: AsyncRead + Unpin + Send {}
22
23impl<T> AsyncReadForward for T where T: AsyncRead + Unpin + Send {}
24
25/// Async writer alias for forward-only library outputs.
26///
27/// This alias covers additive async write surfaces that can emit bytes progressively without
28/// later header backfill seeks, while still requiring `Send` for multithreaded Tokio tasks.
29pub trait AsyncWriteForward: AsyncWrite + Unpin + Send {}
30
31impl<T> AsyncWriteForward for T where T: AsyncWrite + Unpin + Send {}
32
33/// Async reader alias for seekable library inputs.
34///
35/// The first async rollout targets inputs that support both asynchronous reads and random-access
36/// seeks. Non-seekable streams are intentionally excluded from this initial surface, and the
37/// additive async reader path requires `Send` so callers can move independent file work onto Tokio
38/// worker threads.
39pub trait AsyncReadSeek: AsyncRead + AsyncSeek + Unpin + Send {}
40
41impl<T> AsyncReadSeek for T where T: AsyncRead + AsyncSeek + Unpin + Send {}
42
43/// Async writer alias for seekable library outputs.
44///
45/// `mp4forge` write flows backfill box headers after payload bytes are written, so the async write
46/// surface also requires seek support instead of treating outputs as one-way streams. The async
47/// writer path also requires `Send` so independent write jobs can move across Tokio worker
48/// threads.
49pub trait AsyncWriteSeek: AsyncWrite + AsyncSeek + Unpin + Send {}
50
51impl<T> AsyncWriteSeek for T where T: AsyncWrite + AsyncSeek + Unpin + Send {}