8
8
//! All items of this library are only available when the `std` feature of this
9
9
//! library is activated, and it is activated by default.
10
10
11
+ #![ cfg_attr( feature = "read_initializer" , feature( read_initializer) ) ]
12
+
11
13
#![ cfg_attr( not( feature = "std" ) , no_std) ]
12
14
13
15
#![ warn( missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub) ]
@@ -28,8 +30,6 @@ mod if_std {
28
30
use std:: io;
29
31
use std:: ops:: DerefMut ;
30
32
use std:: pin:: Pin ;
31
- #[ cfg( feature = "read_initializer" ) ]
32
- use std:: ptr;
33
33
use std:: task:: { Context , Poll } ;
34
34
35
35
// Re-export some types from `std::io` so that users don't have to deal
@@ -44,47 +44,9 @@ mod if_std {
44
44
SeekFrom as SeekFrom ,
45
45
} ;
46
46
47
- /// A type used to conditionally initialize buffers passed to `AsyncRead`
48
- /// methods, modeled after `std`.
49
- #[ cfg( feature = "read_initializer" ) ]
50
- #[ derive( Debug ) ]
51
- pub struct Initializer ( bool ) ;
52
-
53
47
#[ cfg( feature = "read_initializer" ) ]
54
- impl Initializer {
55
- /// Returns a new `Initializer` which will zero out buffers.
56
- #[ inline]
57
- pub fn zeroing ( ) -> Initializer {
58
- Initializer ( true )
59
- }
60
-
61
- /// Returns a new `Initializer` which will not zero out buffers.
62
- ///
63
- /// # Safety
64
- ///
65
- /// This method may only be called by `AsyncRead`ers which guarantee
66
- /// that they will not read from the buffers passed to `AsyncRead`
67
- /// methods, and that the return value of the method accurately reflects
68
- /// the number of bytes that have been written to the head of the buffer.
69
- #[ inline]
70
- pub unsafe fn nop ( ) -> Initializer {
71
- Initializer ( false )
72
- }
73
-
74
- /// Indicates if a buffer should be initialized.
75
- #[ inline]
76
- pub fn should_initialize ( & self ) -> bool {
77
- self . 0
78
- }
79
-
80
- /// Initializes a buffer if necessary.
81
- #[ inline]
82
- pub fn initialize ( & self , buf : & mut [ u8 ] ) {
83
- if self . should_initialize ( ) {
84
- unsafe { ptr:: write_bytes ( buf. as_mut_ptr ( ) , 0 , buf. len ( ) ) }
85
- }
86
- }
87
- }
48
+ #[ allow( unreachable_pub) ] // https://github.com/rust-lang/rust/issues/57411
49
+ pub use io:: Initializer as Initializer ;
88
50
89
51
/// Read bytes asynchronously.
90
52
///
0 commit comments