qubit_io_binary/lib.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9//! # Qubit Binary IO
10//!
11//! Synchronous and asynchronous binary stream I/O adapters for Rust.
12//!
13//! Synchronous APIs operate on [`qubit_io::Input`] and
14//! [`qubit_io::Output`]. Runtime-neutral asynchronous extension traits operate
15//! on [`qubit_io::AsyncInput`] and [`qubit_io::AsyncOutput`]. Both layers reuse
16//! the same codec implementations for fixed-width values, LEB128, ZigZag, and
17//! length-prefixed UTF-8 strings.
18//!
19//! This crate combines `qubit-io` stream helpers with
20//! `qubit-codec-binary` buffer codecs to provide binary reader and writer
21//! extension traits and wrapper types.
22//!
23//! ## Asynchronous extension traits
24//!
25//! Async extension methods are runtime-neutral and only require `Unpin`
26//! inputs and outputs:
27//!
28//! ```
29//! use qubit_io::{
30//! AsyncInput,
31//! AsyncOutput,
32//! };
33//! use qubit_io_binary::{
34//! AsyncBinaryReadExt,
35//! AsyncBinaryWriteExt,
36//! };
37//!
38//! async fn relay<I, O>(input: &mut I, output: &mut O) -> std::io::Result<()>
39//! where
40//! I: AsyncInput<Item = u8> + Unpin,
41//! O: AsyncOutput<Item = u8> + Unpin,
42//! {
43//! let value = input.read_u32_be_async().await?;
44//! output.write_u32_be_async(value).await
45//! }
46//! ```
47
48mod ext;
49pub mod prelude;
50mod stream;
51mod util;
52
53pub use ext::AsyncBinaryReadExt;
54pub use ext::AsyncBinaryWriteExt;
55pub use ext::AsyncLeb128ReadExt;
56pub use ext::AsyncLeb128WriteExt;
57pub use ext::AsyncStringReadExt;
58pub use ext::AsyncStringWriteExt;
59pub use ext::AsyncZigZagReadExt;
60pub use ext::AsyncZigZagWriteExt;
61pub use ext::BinaryReadExt;
62pub use ext::BinaryWriteExt;
63pub use ext::Leb128ReadExt;
64pub use ext::Leb128WriteExt;
65pub use ext::StringReadExt;
66pub use ext::StringWriteExt;
67pub use ext::ZigZagReadExt;
68pub use ext::ZigZagWriteExt;
69pub use stream::BinaryReader;
70pub use stream::BinaryWriter;
71pub use stream::BufferedBinaryReader;
72pub use stream::BufferedBinaryWriter;
73pub use stream::BufferedLeb128Reader;
74pub use stream::BufferedLeb128Writer;
75pub use stream::BufferedZigZagReader;
76pub use stream::BufferedZigZagWriter;
77pub use stream::Leb128Reader;
78pub use stream::Leb128Writer;
79pub use stream::ZigZagReader;
80pub use stream::ZigZagWriter;