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::{
54 AsyncBinaryReadExt,
55 AsyncBinaryWriteExt,
56 AsyncLeb128ReadExt,
57 AsyncLeb128WriteExt,
58 AsyncStringReadExt,
59 AsyncStringWriteExt,
60 AsyncZigZagReadExt,
61 AsyncZigZagWriteExt,
62 BinaryReadExt,
63 BinaryWriteExt,
64 Leb128ReadExt,
65 Leb128WriteExt,
66 StringReadExt,
67 StringWriteExt,
68 ZigZagReadExt,
69 ZigZagWriteExt,
70};
71pub use stream::{
72 BinaryReader,
73 BinaryWriter,
74 BufferedBinaryReader,
75 BufferedBinaryWriter,
76 BufferedLeb128Reader,
77 BufferedLeb128Writer,
78 BufferedZigZagReader,
79 BufferedZigZagWriter,
80 Leb128Reader,
81 Leb128Writer,
82 ZigZagReader,
83 ZigZagWriter,
84};