@@ -8,8 +8,9 @@ use crate::{OpCode, Overlapped, PushEntry, RawFd};
8
8
/// heap. The pointer to this struct is used as `user_data`, and on Windows, it
9
9
/// is used as the pointer to `OVERLAPPED`.
10
10
///
11
- /// Convert any `user_data` to `*const RawOp<()>` is valid. Then it could be
12
- /// converted to `*mut RawOp<dyn OpCode>` with `upcast_fn`.
11
+ /// `*const RawOp<dyn OpCode>` can be obtained from any `Key<T: OpCode>` by
12
+ /// first casting `Key::user_data` to `*const RawOp<()>`, then upcasted with
13
+ /// `upcast_fn`. It is done in [`Key::as_op_pin`].
13
14
#[ repr( C ) ]
14
15
pub ( crate ) struct RawOp < T : ?Sized > {
15
16
header : Overlapped ,
@@ -132,7 +133,9 @@ impl<T: ?Sized> Key<T> {
132
133
///
133
134
/// # Safety
134
135
///
135
- /// Call it when the op is cancelled and completed.
136
+ /// Call it only when the op is cancelled and completed, which is the case
137
+ /// when the ref count becomes zero. See doc of [`Key::set_cancelled`]
138
+ /// and [`Key::set_result`].
136
139
pub ( crate ) unsafe fn into_box ( mut self ) -> Box < RawOp < dyn OpCode > > {
137
140
let this = self . as_opaque_mut ( ) ;
138
141
let ptr = ( this. upcast_fn ) ( self . user_data ) ;
@@ -143,12 +146,12 @@ impl<T: ?Sized> Key<T> {
143
146
impl < T > Key < T > {
144
147
/// Get the inner result if it is completed.
145
148
///
146
- /// # Panics
149
+ /// # Safety
147
150
///
148
- /// Panics if the op is not completed.
149
- pub ( crate ) fn into_inner ( self ) -> BufResult < usize , T > {
151
+ /// Call it only when the op is completed, otherwise it is UB .
152
+ pub ( crate ) unsafe fn into_inner ( self ) -> BufResult < usize , T > {
150
153
let op = unsafe { Box :: from_raw ( self . user_data as * mut RawOp < T > ) } ;
151
- BufResult ( op. result . take_ready ( ) . unwrap ( ) , op. op )
154
+ BufResult ( op. result . take_ready ( ) . unwrap_unchecked ( ) , op. op )
152
155
}
153
156
}
154
157
0 commit comments