Skip to content

Move doc(hidden) items to __private module and make yielder::pair unsafe #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions async-stream-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl VisitMut for Scrub<'_> {
};
#label
loop {
let #pat = match #crate_path::reexport::next(&mut __pinned).await {
let #pat = match #crate_path::__private::next(&mut __pinned).await {
::core::option::Option::Some(e) => e,
::core::option::Option::None => break,
};
Expand Down Expand Up @@ -227,8 +227,8 @@ pub fn stream_inner(input: TokenStream) -> TokenStream {
};

quote!({
let (mut __yield_tx, __yield_rx) = #crate_path::yielder::pair();
#crate_path::AsyncStream::new(__yield_rx, async move {
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
#dummy_yield
#(#stmts)*
})
Expand Down Expand Up @@ -261,8 +261,8 @@ pub fn try_stream_inner(input: TokenStream) -> TokenStream {
};

quote!({
let (mut __yield_tx, __yield_rx) = #crate_path::yielder::pair();
#crate_path::AsyncStream::new(__yield_rx, async move {
let (mut __yield_tx, __yield_rx) = unsafe { #crate_path::__private::yielder::pair() };
#crate_path::__private::AsyncStream::new(__yield_rx, async move {
#dummy_yield
#(#stmts)*
})
Expand Down
23 changes: 10 additions & 13 deletions async-stream/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,7 @@

mod async_stream;
mod next;
#[doc(hidden)]
pub mod yielder;

// Used by the macro, but not intended to be accessed publicly.
#[doc(hidden)]
pub use crate::async_stream::AsyncStream;

#[doc(hidden)]
pub use async_stream_impl;
mod yielder;

/// Asynchronous stream
///
Expand Down Expand Up @@ -198,7 +190,7 @@ pub use async_stream_impl;
#[macro_export]
macro_rules! stream {
($($tt:tt)*) => {
$crate::async_stream_impl::stream_inner!(($crate) $($tt)*)
$crate::__private::stream_inner!(($crate) $($tt)*)
}
}

Expand Down Expand Up @@ -234,12 +226,17 @@ macro_rules! stream {
#[macro_export]
macro_rules! try_stream {
($($tt:tt)*) => {
$crate::async_stream_impl::try_stream_inner!(($crate) $($tt)*)
$crate::__private::try_stream_inner!(($crate) $($tt)*)
}
}

// Not public API.
#[doc(hidden)]
pub mod reexport {
#[doc(hidden)]
pub mod __private {
pub use crate::async_stream::AsyncStream;
pub use crate::next::next;
pub use async_stream_impl::{stream_inner, try_stream_inner};
pub mod yielder {
pub use crate::yielder::pair;
}
}
7 changes: 6 additions & 1 deletion async-stream/src/yielder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ pub(crate) struct Enter<'a, T> {
prev: *mut (),
}

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