refactor(lib): apply unreachable_pub lint (#2400)

Closes #2390
This commit is contained in:
Taiki Endo
2021-01-15 02:57:55 +09:00
committed by GitHub
parent a15f3f7f0f
commit f0ddb66932
28 changed files with 196 additions and 185 deletions

View File

@@ -6,10 +6,10 @@ use tokio::sync::{mpsc, oneshot};
use crate::common::{task, Pin, Poll};
pub type RetryPromise<T, U> = oneshot::Receiver<Result<U, (crate::Error, Option<T>)>>;
pub type Promise<T> = oneshot::Receiver<Result<T, crate::Error>>;
pub(crate) type RetryPromise<T, U> = oneshot::Receiver<Result<U, (crate::Error, Option<T>)>>;
pub(crate) type Promise<T> = oneshot::Receiver<Result<T, crate::Error>>;
pub fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
pub(crate) fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
let (tx, rx) = mpsc::unbounded_channel();
let (giver, taker) = want::new();
let tx = Sender {
@@ -25,7 +25,7 @@ pub fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
///
/// While the inner sender is unbounded, the Giver is used to determine
/// if the Receiver is ready for another request.
pub struct Sender<T, U> {
pub(crate) struct Sender<T, U> {
/// One message is always allowed, even if the Receiver hasn't asked
/// for it yet. This boolean keeps track of whether we've sent one
/// without notice.
@@ -44,24 +44,24 @@ pub struct Sender<T, U> {
/// Cannot poll the Giver, but can still use it to determine if the Receiver
/// has been dropped. However, this version can be cloned.
#[cfg(feature = "http2")]
pub struct UnboundedSender<T, U> {
pub(crate) struct UnboundedSender<T, U> {
/// Only used for `is_closed`, since mpsc::UnboundedSender cannot be checked.
giver: want::SharedGiver,
inner: mpsc::UnboundedSender<Envelope<T, U>>,
}
impl<T, U> Sender<T, U> {
pub fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
pub(crate) fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
self.giver
.poll_want(cx)
.map_err(|_| crate::Error::new_closed())
}
pub fn is_ready(&self) -> bool {
pub(crate) fn is_ready(&self) -> bool {
self.giver.is_wanting()
}
pub fn is_closed(&self) -> bool {
pub(crate) fn is_closed(&self) -> bool {
self.giver.is_canceled()
}
@@ -78,7 +78,7 @@ impl<T, U> Sender<T, U> {
}
}
pub fn try_send(&mut self, val: T) -> Result<RetryPromise<T, U>, T> {
pub(crate) fn try_send(&mut self, val: T) -> Result<RetryPromise<T, U>, T> {
if !self.can_send() {
return Err(val);
}
@@ -89,7 +89,7 @@ impl<T, U> Sender<T, U> {
.map_err(|mut e| (e.0).0.take().expect("envelope not dropped").0)
}
pub fn send(&mut self, val: T) -> Result<Promise<U>, T> {
pub(crate) fn send(&mut self, val: T) -> Result<Promise<U>, T> {
if !self.can_send() {
return Err(val);
}
@@ -101,7 +101,7 @@ impl<T, U> Sender<T, U> {
}
#[cfg(feature = "http2")]
pub fn unbound(self) -> UnboundedSender<T, U> {
pub(crate) fn unbound(self) -> UnboundedSender<T, U> {
UnboundedSender {
giver: self.giver.shared(),
inner: self.inner,
@@ -111,15 +111,15 @@ impl<T, U> Sender<T, U> {
#[cfg(feature = "http2")]
impl<T, U> UnboundedSender<T, U> {
pub fn is_ready(&self) -> bool {
pub(crate) fn is_ready(&self) -> bool {
!self.giver.is_canceled()
}
pub fn is_closed(&self) -> bool {
pub(crate) fn is_closed(&self) -> bool {
self.giver.is_canceled()
}
pub fn try_send(&mut self, val: T) -> Result<RetryPromise<T, U>, T> {
pub(crate) fn try_send(&mut self, val: T) -> Result<RetryPromise<T, U>, T> {
let (tx, rx) = oneshot::channel();
self.inner
.send(Envelope(Some((val, Callback::Retry(tx)))))
@@ -139,7 +139,7 @@ impl<T, U> Clone for UnboundedSender<T, U> {
}
#[pin_project::pin_project(PinnedDrop)]
pub struct Receiver<T, U> {
pub(crate) struct Receiver<T, U> {
#[pin]
inner: mpsc::UnboundedReceiver<Envelope<T, U>>,
taker: want::Taker,
@@ -199,7 +199,7 @@ impl<T, U> Drop for Envelope<T, U> {
}
}
pub enum Callback<T, U> {
pub(crate) enum Callback<T, U> {
Retry(oneshot::Sender<Result<U, (crate::Error, Option<T>)>>),
NoRetry(oneshot::Sender<Result<U, crate::Error>>),
}