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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (c) 2026 Mike Grier
//! What a ring may be asked to carry: [`Open`] or [`Owned`] (`M41.1`,
//! [D-91](../../DESIGN-NOTES.md#d-91)).
//!
//! Every operation a safe push queues is an *owned* operation: the ring holds what it needs, and
//! the pop that observes its completion hands that back. A handful of calls queue an operation
//! the ring holds **nothing** for -- the registrations, the `_raw` flush and cancel, and
//! [`IoRing::push_raw`](super::IoRing::push_raw) -- and their completions arrive from a pop with
//! no payload and no sidecar. That is a legitimate outcome for a caller who chose it, and a
//! branch every other caller has to write and cannot reach.
//!
//! A ring is therefore typed by whether it can have such an operation in flight. An [`Open`] ring
//! can, and is what every constructor makes. An [`Owned`] ring cannot: the calls that queue one do
//! not exist for it, and a pop never hands back an absent entry. The one way from the first to the
//! second is [`IoRing::into_owned`](super::IoRing::into_owned), which consumes the ring and refuses
//! while any such operation is in flight; there is no way back, so the property is not one a
//! later caller can undo.
use io;
use crateCompletion;
/// A ring that may have an operation in flight that the ring holds nothing for: the kind every
/// constructor makes. All of the ring's calls exist for it.
///
/// Uninhabited: it only ever appears as a type argument.
/// A ring none of whose in-flight operations can be one the ring holds nothing for, reached from
/// an [`Open`] ring by [`IoRing::into_owned`](super::IoRing::into_owned). The calls that queue such
/// an operation do not exist for it, and a pop returns what the ring held, without the case of
/// there being nothing.
///
/// Uninhabited: it only ever appears as a type argument.
/// What a ring's kind decides: the shape a pop returns it in. Implemented by [`Open`] and
/// [`Owned`] only.
/// The kinds that may queue an operation the ring holds nothing for: [`Open`]. A method with this
/// bound is one an [`Owned`] ring does not have.
///
/// The registrations and the `_raw` flush and cancel do not build for an [`Owned`] ring:
///
/// ```compile_fail,E0277
/// use windows_ioring_sys::{Batch, IoRing, Owned};
///
/// fn register(ring: &mut IoRing<Vec<u8>, (), Owned>) {
/// let _ = Batch::new(ring).register_buffers(vec![vec![0_u8; 8]]);
/// }
/// ```
///
/// ```compile_fail,E0277
/// use windows_ioring_sys::{Batch, FlushCoverage, FlushMode, IoRing, Owned};
///
/// fn flush(ring: &mut IoRing<(), (), Owned>, file: std::os::windows::io::RawHandle) {
/// // SAFETY: not reached; this is a compile failure.
/// let _ = unsafe {
/// Batch::new(ring).flush_raw(file, FlushCoverage::Unordered, FlushMode::Default)
/// };
/// }
/// ```
///
/// ```compile_fail,E0277
/// use windows_ioring_sys::{IoRing, Owned};
///
/// fn push(ring: &mut IoRing<(), (), Owned>) {
/// // SAFETY: not reached; this is a compile failure.
/// let _ = unsafe { ring.push_raw(|_, _| 0) };
/// }
/// ```
///
/// And no constructor makes one, nor is there a way back to [`Open`]:
///
/// ```compile_fail,E0308
/// use windows_ioring_sys::{IoRing, Owned};
///
/// let _ring: IoRing<(), (), Owned> = IoRing::new(8, 8).unwrap();
/// ```
///
/// ```compile_fail,E0599
/// use windows_ioring_sys::{IoRing, Owned};
///
/// fn reopen(ring: IoRing<(), (), Owned>) {
/// let _ = ring.into_open();
/// }
/// ```
///
/// Over an [`Open`] ring the same calls build:
///
/// ```no_run
/// use windows_ioring_sys::{Batch, IoRing};
///
/// # fn main() -> std::io::Result<()> {
/// let mut ring = IoRing::<Vec<u8>>::with_inventory(8, 8)?;
/// let _pending = Batch::new(&mut ring).register_buffers(vec![vec![0_u8; 8]]);
/// # Ok(())
/// # }
/// ```