@@ -10,6 +10,9 @@ use core::mem::{self, MaybeUninit};
10
10
use core:: ops:: { Deref , DerefMut } ;
11
11
use core:: pin:: Pin ;
12
12
13
+ #[ cfg( feature = "std" ) ]
14
+ use std:: io:: Read ;
15
+
13
16
/// Binding to C++ `std::unique_ptr<T, std::default_delete<T>>`.
14
17
#[ repr( C ) ]
15
18
pub struct UniquePtr < T >
@@ -181,6 +184,38 @@ where
181
184
}
182
185
}
183
186
187
+ /// Forwarding `Read` trait implementation in a manner similar to `Box<T>`. Note that the
188
+ /// implementation will panic for null `UniquePtr<T>`.
189
+ #[ cfg( feature = "std" ) ]
190
+ impl < T > Read for UniquePtr < T >
191
+ where
192
+ for < ' a > Pin < & ' a mut T > : Read ,
193
+ T : UniquePtrTarget ,
194
+ {
195
+ #[ inline]
196
+ fn read ( & mut self , buf : & mut [ u8 ] ) -> std:: io:: Result < usize > {
197
+ self . pin_mut ( ) . read ( buf)
198
+ }
199
+
200
+ #[ inline]
201
+ fn read_to_end ( & mut self , buf : & mut std:: vec:: Vec < u8 > ) -> std:: io:: Result < usize > {
202
+ self . pin_mut ( ) . read_to_end ( buf)
203
+ }
204
+
205
+ #[ inline]
206
+ fn read_to_string ( & mut self , buf : & mut std:: string:: String ) -> std:: io:: Result < usize > {
207
+ self . pin_mut ( ) . read_to_string ( buf)
208
+ }
209
+
210
+ #[ inline]
211
+ fn read_exact ( & mut self , buf : & mut [ u8 ] ) -> std:: io:: Result < ( ) > {
212
+ self . pin_mut ( ) . read_exact ( buf)
213
+ }
214
+
215
+ // TODO: Foward other `Read` trait methods when they get stabilized (e.g.
216
+ // `read_buf` and/or `is_read_vectored`).
217
+ }
218
+
184
219
/// Trait bound for types which may be used as the `T` inside of a
185
220
/// `UniquePtr<T>` in generic code.
186
221
///
0 commit comments