Skip to content

Commit e1d440f

Browse files
authored
Move doc(hidden) items to __private module and make yielder::pair unsafe (#84)
To clarify that they are not public APIs.
1 parent ac3fa6b commit e1d440f

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

async-stream-impl/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl VisitMut for Scrub<'_> {
173173
};
174174
#label
175175
loop {
176-
let #pat = match #crate_path::reexport::next(&mut __pinned).await {
176+
let #pat = match #crate_path::__private::next(&mut __pinned).await {
177177
::core::option::Option::Some(e) => e,
178178
::core::option::Option::None => break,
179179
};
@@ -227,8 +227,8 @@ pub fn stream_inner(input: TokenStream) -> TokenStream {
227227
};
228228

229229
quote!({
230-
let (mut __yield_tx, __yield_rx) = #crate_path::yielder::pair();
231-
#crate_path::AsyncStream::new(__yield_rx, async move {
230+
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
231+
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
232232
#dummy_yield
233233
#(#stmts)*
234234
})
@@ -261,8 +261,8 @@ pub fn try_stream_inner(input: TokenStream) -> TokenStream {
261261
};
262262

263263
quote!({
264-
let (mut __yield_tx, __yield_rx) = #crate_path::yielder::pair();
265-
#crate_path::AsyncStream::new(__yield_rx, async move {
264+
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
265+
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
266266
#dummy_yield
267267
#(#stmts)*
268268
})

async-stream/src/lib.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,7 @@
158158
159159
mod async_stream;
160160
mod next;
161-
#[doc(hidden)]
162-
pub mod yielder;
163-
164-
// Used by the macro, but not intended to be accessed publicly.
165-
#[doc(hidden)]
166-
pub use crate::async_stream::AsyncStream;
167-
168-
#[doc(hidden)]
169-
pub use async_stream_impl;
161+
mod yielder;
170162

171163
/// Asynchronous stream
172164
///
@@ -198,7 +190,7 @@ pub use async_stream_impl;
198190
#[macro_export]
199191
macro_rules! stream {
200192
($($tt:tt)*) => {
201-
$crate::async_stream_impl::stream_inner!(($crate) $($tt)*)
193+
$crate::__private::stream_inner!(($crate) $($tt)*)
202194
}
203195
}
204196

@@ -234,12 +226,17 @@ macro_rules! stream {
234226
#[macro_export]
235227
macro_rules! try_stream {
236228
($($tt:tt)*) => {
237-
$crate::async_stream_impl::try_stream_inner!(($crate) $($tt)*)
229+
$crate::__private::try_stream_inner!(($crate) $($tt)*)
238230
}
239231
}
240232

233+
// Not public API.
241234
#[doc(hidden)]
242-
pub mod reexport {
243-
#[doc(hidden)]
235+
pub mod __private {
236+
pub use crate::async_stream::AsyncStream;
244237
pub use crate::next::next;
238+
pub use async_stream_impl::{stream_inner, try_stream_inner};
239+
pub mod yielder {
240+
pub use crate::yielder::pair;
241+
}
245242
}

async-stream/src/yielder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ pub(crate) struct Enter<'a, T> {
2020
prev: *mut (),
2121
}
2222

23-
pub fn pair<T>() -> (Sender<T>, Receiver<T>) {
23+
// Note: It is considered unsound for anyone other than our macros to call
24+
// this function. This is a private API intended only for calls from our
25+
// macros, and users should never call it, but some people tend to
26+
// misinterpret it as fine to call unless it is marked unsafe.
27+
#[doc(hidden)]
28+
pub unsafe fn pair<T>() -> (Sender<T>, Receiver<T>) {
2429
let tx = Sender { _p: PhantomData };
2530
let rx = Receiver { _p: PhantomData };
2631
(tx, rx)

0 commit comments

Comments
 (0)