Skip to content

Commit 57686fd

Browse files
committed
Use std::io::Initializer instead of our own Initializer
1 parent f8f812f commit 57686fd

File tree

3 files changed

+6
-42
lines changed

3 files changed

+6
-42
lines changed

futures-io/src/lib.rs

+4-42
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
//! All items of this library are only available when the `std` feature of this
99
//! library is activated, and it is activated by default.
1010
11+
#![cfg_attr(feature = "read_initializer", feature(read_initializer))]
12+
1113
#![cfg_attr(not(feature = "std"), no_std)]
1214

1315
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
@@ -28,8 +30,6 @@ mod if_std {
2830
use std::io;
2931
use std::ops::DerefMut;
3032
use std::pin::Pin;
31-
#[cfg(feature = "read_initializer")]
32-
use std::ptr;
3333
use std::task::{Context, Poll};
3434

3535
// Re-export some types from `std::io` so that users don't have to deal
@@ -44,47 +44,9 @@ mod if_std {
4444
SeekFrom as SeekFrom,
4545
};
4646

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-
5347
#[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;
8850

8951
/// Read bytes asynchronously.
9052
///

futures-util/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! and the `AsyncRead` and `AsyncWrite` traits.
33
44
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
5+
#![cfg_attr(feature = "read_initializer", feature(read_initializer))]
56

67
#![cfg_attr(not(feature = "std"), no_std)]
78
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]

futures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! completion, but *do not block* the thread running them.
2323
2424
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
25+
#![cfg_attr(feature = "read_initializer", feature(read_initializer))]
2526

2627
#![cfg_attr(not(feature = "std"), no_std)]
2728

0 commit comments

Comments
 (0)