1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// =============================================================================
// Copyright (c) 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
use crateOutput;
/// A synchronous output whose items are Unicode scalar values.
///
/// This trait adds no methods. Every [`Output<Item = char>`](Output),
/// including unsized streams, implements it automatically. Implement [`Output`]
/// to provide the operations; no separate implementation of `CharOutput` is
/// needed.
///
/// Character counts measure Unicode scalar values, not encoded bytes or
/// grapheme clusters. This trait does not encode or decode text.
///
/// # Examples
///
/// ```
/// use std::io;
///
/// use qubit_io::CharOutput;
/// use qubit_io::Output;
///
/// fn write_char(output: &mut impl CharOutput, value: char) -> io::Result<()> {
/// output.write_fully(&[value])
/// }
///
/// #[derive(Default)]
/// struct CharBuffer(Vec<char>);
///
/// impl Output for CharBuffer {
/// type Item = char;
///
/// unsafe fn write_unchecked(
/// &mut self,
/// input: &[char],
/// index: usize,
/// count: usize,
/// ) -> io::Result<usize> {
/// self.0.extend_from_slice(&input[index..index + count]);
/// Ok(count)
/// }
///
/// fn flush(&mut self) -> io::Result<()> {
/// Ok(())
/// }
/// }
///
/// let mut output = CharBuffer::default();
/// write_char(&mut output, '🦀')?;
/// assert_eq!(output.0, ['🦀']);
/// # Ok::<(), io::Error>(())
/// ```
///
/// Streams with a different item type do not satisfy this bound:
///
/// ```compile_fail
/// use qubit_io::CharOutput;
/// use qubit_io::Output;
///
/// fn accept(stream: impl CharOutput) {}
///
/// fn reject(stream: impl Output<Item = u8>) {
/// accept(stream);
/// }
/// ```