Skip to main content

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