chore: enforce unreachable_pub lint

The `unreachable_pub` lint makes us aware of uses of `pub` that are not actually reachable from the crate root. This is considered good because it means reading a `pub` somewhere means it is actually public API. Some of our crates are quite large and keeping their entire API surface in your head is difficult.

We should strive for most items being `pub(crate)`. This lint helps us enforce that.

Pull-Request: #3735.
This commit is contained in:
Thomas Eizinger
2023-04-26 09:31:56 +02:00
committed by GitHub
parent e5dbeb3e08
commit 135942d319
93 changed files with 861 additions and 767 deletions

View File

@ -559,8 +559,9 @@ impl From<UnmappableStatusCode> for ConversionError {
pub struct UnmappableStatusCode(proto::ResponseStatus);
mod proto {
#![allow(unreachable_pub)]
include!("generated/mod.rs");
pub use self::rendezvous::pb::{mod_Message::*, Message};
pub(crate) use self::rendezvous::pb::{mod_Message::*, Message};
}
#[cfg(test)]

View File

@ -24,9 +24,8 @@ use void::Void;
const PROTOCOL_IDENT: &[u8] = b"/rendezvous/1.0.0";
pub mod inbound;
pub mod outbound;
pub(crate) mod inbound;
pub(crate) mod outbound;
/// Errors that can occur while interacting with a substream.
#[allow(clippy::large_enum_variant)]
#[derive(Debug, thiserror::Error)]
@ -41,9 +40,10 @@ pub enum Error {
UnexpectedEndOfStream,
}
pub type OutboundInEvent = crate::substream_handler::InEvent<outbound::OpenInfo, Void, Void>;
pub type OutboundOutEvent =
pub(crate) type OutboundInEvent = crate::substream_handler::InEvent<outbound::OpenInfo, Void, Void>;
pub(crate) type OutboundOutEvent =
crate::substream_handler::OutEvent<Void, outbound::OutEvent, Void, Error>;
pub type InboundInEvent = crate::substream_handler::InEvent<(), inbound::InEvent, Void>;
pub type InboundOutEvent = crate::substream_handler::OutEvent<inbound::OutEvent, Void, Error, Void>;
pub(crate) type InboundInEvent = crate::substream_handler::InEvent<(), inbound::InEvent, Void>;
pub(crate) type InboundOutEvent =
crate::substream_handler::OutEvent<inbound::OutEvent, Void, Error, Void>;

View File

@ -503,18 +503,20 @@ where
/// A helper struct for substream handlers that can be implemented as async functions.
///
/// This only works for substreams without an `InEvent` because - once constructed - the state of an inner future is opaque.
pub struct FutureSubstream<TOutEvent, TError> {
pub(crate) struct FutureSubstream<TOutEvent, TError> {
future: Fuse<BoxFuture<'static, Result<TOutEvent, TError>>>,
}
impl<TOutEvent, TError> FutureSubstream<TOutEvent, TError> {
pub fn new(future: impl Future<Output = Result<TOutEvent, TError>> + Send + 'static) -> Self {
pub(crate) fn new(
future: impl Future<Output = Result<TOutEvent, TError>> + Send + 'static,
) -> Self {
Self {
future: future.boxed().fuse(),
}
}
pub fn advance(mut self, cx: &mut Context<'_>) -> Result<Next<Self, TOutEvent>, TError> {
pub(crate) fn advance(mut self, cx: &mut Context<'_>) -> Result<Next<Self, TOutEvent>, TError> {
if self.future.is_terminated() {
return Ok(Next::Done);
}