Skip to content

Commit

Permalink
refactor(lib): apply unreachable_pub lint (#2400)
Browse files Browse the repository at this point in the history
Closes #2390
  • Loading branch information
taiki-e authored Jan 14, 2021
1 parent a15f3f7 commit f0ddb66
Show file tree
Hide file tree
Showing 28 changed files with 196 additions and 185 deletions.
2 changes: 1 addition & 1 deletion src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ where
ResponseFuture { inner }
}

pub(crate) fn send_request_retryable(
pub(super) fn send_request_retryable(
&mut self,
req: Request<B>,
) -> impl Future<Output = Result<Response<Body>, (crate::Error, Option<Request<B>>)>> + Unpin
Expand Down
2 changes: 1 addition & 1 deletion src/client/connect/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ mod sealed {
}
}

pub(crate) async fn resolve<R>(resolver: &mut R, name: Name) -> Result<R::Addrs, R::Error>
pub(super) async fn resolve<R>(resolver: &mut R, name: Name) -> Result<R::Addrs, R::Error>
where
R: Resolve,
{
Expand Down
32 changes: 16 additions & 16 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand All @@ -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()
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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,
Expand All @@ -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)))))
Expand All @@ -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,
Expand Down Expand Up @@ -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>>),
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cfg_feature! {

mod client;
pub mod conn;
pub(crate) mod dispatch;
pub(super) mod dispatch;
mod pool;
pub mod service;
}
8 changes: 4 additions & 4 deletions src/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Config {
}

impl<T> Pool<T> {
pub fn new(config: Config, __exec: &Exec) -> Pool<T> {
pub(super) fn new(config: Config, __exec: &Exec) -> Pool<T> {
let inner = if config.is_enabled() {
Some(Arc::new(Mutex::new(PoolInner {
connecting: HashSet::new(),
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<T> Pool<T> {
impl<T: Poolable> Pool<T> {
/// Returns a `Checkout` which is a future that resolves if an idle
/// connection becomes available.
pub fn checkout(&self, key: Key) -> Checkout<T> {
pub(super) fn checkout(&self, key: Key) -> Checkout<T> {
Checkout {
key,
pool: self.clone(),
Expand Down Expand Up @@ -489,11 +489,11 @@ pub(super) struct Pooled<T: Poolable> {
}

impl<T: Poolable> Pooled<T> {
pub fn is_reused(&self) -> bool {
pub(super) fn is_reused(&self) -> bool {
self.is_reused
}

pub fn is_pool_enabled(&self) -> bool {
pub(super) fn is_pool_enabled(&self) -> bool {
self.pool.0.is_some()
}

Expand Down
6 changes: 3 additions & 3 deletions src/common/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ use http::header::HeaderValue;
use httpdate::HttpDate;

// "Sun, 06 Nov 1994 08:49:37 GMT".len()
pub const DATE_VALUE_LENGTH: usize = 29;
pub(crate) const DATE_VALUE_LENGTH: usize = 29;

#[cfg(feature = "http1")]
pub fn extend(dst: &mut Vec<u8>) {
pub(crate) fn extend(dst: &mut Vec<u8>) {
CACHED.with(|cache| {
dst.extend_from_slice(cache.borrow().buffer());
})
}

#[cfg(feature = "http1")]
pub fn update() {
pub(crate) fn update() {
CACHED.with(|cache| {
cache.borrow_mut().check();
})
Expand Down
12 changes: 6 additions & 6 deletions src/common/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ use tokio::sync::watch;

use super::{task, Future, Pin, Poll};

pub fn channel() -> (Signal, Watch) {
pub(crate) fn channel() -> (Signal, Watch) {
let (tx, rx) = watch::channel(());
(Signal { tx }, Watch { rx })
}

pub struct Signal {
pub(crate) struct Signal {
tx: watch::Sender<()>,
}

pub struct Draining(Pin<Box<dyn Future<Output = ()> + Send + Sync>>);
pub(crate) struct Draining(Pin<Box<dyn Future<Output = ()> + Send + Sync>>);

#[derive(Clone)]
pub struct Watch {
pub(crate) struct Watch {
rx: watch::Receiver<()>,
}

Expand All @@ -37,7 +37,7 @@ enum State<F> {
}

impl Signal {
pub fn drain(self) -> Draining {
pub(crate) fn drain(self) -> Draining {
let _ = self.tx.send(());
Draining(Box::pin(async move { self.tx.closed().await }))
}
Expand All @@ -52,7 +52,7 @@ impl Future for Draining {
}

impl Watch {
pub fn watch<F, FN>(self, future: F, on_drain: FN) -> Watching<F, FN>
pub(crate) fn watch<F, FN>(self, future: F, on_drain: FN) -> Watching<F, FN>
where
F: Future,
FN: FnOnce(Pin<&mut F>),
Expand Down
2 changes: 1 addition & 1 deletion src/common/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait NewSvcExec<I, N, S: HttpService<Body>, E, W: Watcher<I, S, E>>: Clone
fn execute_new_svc(&mut self, fut: NewSvcTask<I, N, S, E, W>);
}

pub type BoxSendFuture = Pin<Box<dyn Future<Output = ()> + Send>>;
pub(crate) type BoxSendFuture = Pin<Box<dyn Future<Output = ()> + Send>>;

// Either the user provides an executor for background tasks, or we use
// `tokio::spawn`.
Expand Down
8 changes: 7 additions & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ pub(crate) mod watch;
#[cfg(any(feature = "http1", feature = "http2"))]
#[cfg(feature = "client")]
pub(crate) use self::lazy::{lazy, Started as Lazy};
pub use self::never::Never;
#[cfg(any(
feature = "client",
feature = "http1",
feature = "http2",
feature = "runtime"
))]
pub(crate) use self::never::Never;
pub(crate) use self::task::Poll;

// group up types normally needed for `Future`
Expand Down
2 changes: 1 addition & 1 deletion src/common/never.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub enum Never {}
pub(crate) enum Never {}

impl fmt::Display for Never {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
8 changes: 4 additions & 4 deletions src/common/sync_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/// [`poll`]: https://doc.rust-lang.org/std/future/trait.Future.html#method.poll
/// [`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
#[repr(transparent)]
pub struct SyncWrapper<T>(T);
pub(crate) struct SyncWrapper<T>(T);

impl<T> SyncWrapper<T> {
/// Creates a new SyncWrapper containing the given value.
Expand All @@ -58,7 +58,7 @@ impl<T> SyncWrapper<T> {
///
/// let wrapped = SyncWrapper::new(42);
/// ```
pub fn new(value: T) -> Self {
pub(crate) fn new(value: T) -> Self {
Self(value)
}

Expand All @@ -82,7 +82,7 @@ impl<T> SyncWrapper<T> {
/// *value = 0;
/// assert_eq!(*wrapped.get_mut(), 0);
/// ```
pub fn get_mut(&mut self) -> &mut T {
pub(crate) fn get_mut(&mut self) -> &mut T {
&mut self.0
}

Expand All @@ -105,7 +105,7 @@ impl<T> SyncWrapper<T> {
/// assert_eq!(wrapped.into_inner(), 42);
/// ```
#[allow(dead_code)]
pub fn into_inner(self) -> T {
pub(crate) fn into_inner(self) -> T {
self.0
}
}
Expand Down
Loading

0 comments on commit f0ddb66

Please sign in to comment.