Skip to main content

qubit_io/traits/
byte_input.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
9use crate::Input;
10
11/// A synchronous input whose items are bytes.
12///
13/// This trait adds no methods. Every [`Input<Item = u8>`](Input), including
14/// unsized inputs and standard library readers, implements it automatically.
15/// Implement [`Input`] to provide the operations; no separate implementation
16/// of `ByteInput` is needed.
17///
18/// # Examples
19///
20/// ```
21/// use qubit_io::ByteInput;
22///
23/// fn input() -> impl ByteInput {
24///     std::io::Cursor::new(b"bytes")
25/// }
26///
27/// let mut input: Box<dyn ByteInput> = Box::new(input());
28/// let mut bytes = [0; 5];
29/// input.read_exactly(&mut bytes)?;
30/// assert_eq!(&bytes, b"bytes");
31/// # Ok::<(), std::io::Error>(())
32/// ```
33///
34/// Inputs with non-byte items do not satisfy this bound:
35///
36/// ```compile_fail
37/// use qubit_io::{ByteInput, Input};
38///
39/// fn accept(input: impl ByteInput) {}
40///
41/// fn reject(input: impl Input<Item = char>) {
42///     accept(input);
43/// }
44/// ```
45pub trait ByteInput: Input<Item = u8> {
46    // empty
47}
48
49impl<T: Input<Item = u8> + ?Sized> ByteInput for T {}