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

@@ -35,7 +35,7 @@ where
B: Buf,
T: Http1Transaction,
{
pub fn new(io: I) -> Conn<I, B, T> {
pub(crate) fn new(io: I) -> Conn<I, B, T> {
Conn {
io: Buffered::new(io),
state: State {
@@ -60,21 +60,21 @@ where
}
#[cfg(feature = "server")]
pub fn set_flush_pipeline(&mut self, enabled: bool) {
pub(crate) fn set_flush_pipeline(&mut self, enabled: bool) {
self.io.set_flush_pipeline(enabled);
}
pub fn set_max_buf_size(&mut self, max: usize) {
pub(crate) fn set_max_buf_size(&mut self, max: usize) {
self.io.set_max_buf_size(max);
}
#[cfg(feature = "client")]
pub fn set_read_buf_exact_size(&mut self, sz: usize) {
pub(crate) fn set_read_buf_exact_size(&mut self, sz: usize) {
self.io.set_read_buf_exact_size(sz);
}
#[cfg(feature = "client")]
pub fn set_title_case_headers(&mut self) {
pub(crate) fn set_title_case_headers(&mut self) {
self.state.title_case_headers = true;
}
@@ -83,23 +83,23 @@ where
self.state.allow_half_close = true;
}
pub fn into_inner(self) -> (I, Bytes) {
pub(crate) fn into_inner(self) -> (I, Bytes) {
self.io.into_inner()
}
pub fn pending_upgrade(&mut self) -> Option<crate::upgrade::Pending> {
pub(crate) fn pending_upgrade(&mut self) -> Option<crate::upgrade::Pending> {
self.state.upgrade.take()
}
pub fn is_read_closed(&self) -> bool {
pub(crate) fn is_read_closed(&self) -> bool {
self.state.is_read_closed()
}
pub fn is_write_closed(&self) -> bool {
pub(crate) fn is_write_closed(&self) -> bool {
self.state.is_write_closed()
}
pub fn can_read_head(&self) -> bool {
pub(crate) fn can_read_head(&self) -> bool {
match self.state.reading {
Reading::Init => {
if T::should_read_first() {
@@ -115,7 +115,7 @@ where
}
}
pub fn can_read_body(&self) -> bool {
pub(crate) fn can_read_body(&self) -> bool {
match self.state.reading {
Reading::Body(..) | Reading::Continue(..) => true,
_ => false,
@@ -211,7 +211,7 @@ where
}
}
pub fn poll_read_body(
pub(crate) fn poll_read_body(
&mut self,
cx: &mut task::Context<'_>,
) -> Poll<Option<io::Result<Bytes>>> {
@@ -268,13 +268,13 @@ where
ret
}
pub fn wants_read_again(&mut self) -> bool {
pub(crate) fn wants_read_again(&mut self) -> bool {
let ret = self.state.notify_read;
self.state.notify_read = false;
ret
}
pub fn poll_read_keep_alive(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
pub(crate) fn poll_read_keep_alive(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
debug_assert!(!self.can_read_head() && !self.can_read_body());
if self.is_read_closed() {
@@ -412,7 +412,7 @@ where
self.maybe_notify(cx);
}
pub fn can_write_head(&self) -> bool {
pub(crate) fn can_write_head(&self) -> bool {
if !T::should_read_first() {
if let Reading::Closed = self.state.reading {
return false;
@@ -424,18 +424,18 @@ where
}
}
pub fn can_write_body(&self) -> bool {
pub(crate) fn can_write_body(&self) -> bool {
match self.state.writing {
Writing::Body(..) => true,
Writing::Init | Writing::KeepAlive | Writing::Closed => false,
}
}
pub fn can_buffer_body(&self) -> bool {
pub(crate) fn can_buffer_body(&self) -> bool {
self.io.can_buffer()
}
pub fn write_head(&mut self, head: MessageHead<T::Outgoing>, body: Option<BodyLength>) {
pub(crate) fn write_head(&mut self, head: MessageHead<T::Outgoing>, body: Option<BodyLength>) {
if let Some(encoder) = self.encode_head(head, body) {
self.state.writing = if !encoder.is_eof() {
Writing::Body(encoder)
@@ -447,7 +447,7 @@ where
}
}
pub fn write_full_msg(&mut self, head: MessageHead<T::Outgoing>, body: B) {
pub(crate) fn write_full_msg(&mut self, head: MessageHead<T::Outgoing>, body: B) {
if let Some(encoder) =
self.encode_head(head, Some(BodyLength::Known(body.remaining() as u64)))
{
@@ -555,7 +555,7 @@ where
// the user's headers be.
}
pub fn write_body(&mut self, chunk: B) {
pub(crate) fn write_body(&mut self, chunk: B) {
debug_assert!(self.can_write_body() && self.can_buffer_body());
// empty chunks should be discarded at Dispatcher level
debug_assert!(chunk.remaining() != 0);
@@ -580,7 +580,7 @@ where
self.state.writing = state;
}
pub fn write_body_and_end(&mut self, chunk: B) {
pub(crate) fn write_body_and_end(&mut self, chunk: B) {
debug_assert!(self.can_write_body() && self.can_buffer_body());
// empty chunks should be discarded at Dispatcher level
debug_assert!(chunk.remaining() != 0);
@@ -600,7 +600,7 @@ where
self.state.writing = state;
}
pub fn end_body(&mut self) -> crate::Result<()> {
pub(crate) fn end_body(&mut self) -> crate::Result<()> {
debug_assert!(self.can_write_body());
let mut res = Ok(());
@@ -657,14 +657,14 @@ where
Err(err)
}
pub fn poll_flush(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
pub(crate) fn poll_flush(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
ready!(Pin::new(&mut self.io).poll_flush(cx))?;
self.try_keep_alive(cx);
trace!("flushed({}): {:?}", T::LOG, self.state);
Poll::Ready(Ok(()))
}
pub fn poll_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
pub(crate) fn poll_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
match ready!(Pin::new(self.io.io_mut()).poll_shutdown(cx)) {
Ok(()) => {
trace!("shut down IO complete");
@@ -691,16 +691,16 @@ where
}
}
pub fn close_read(&mut self) {
pub(crate) fn close_read(&mut self) {
self.state.close_read();
}
pub fn close_write(&mut self) {
pub(crate) fn close_write(&mut self) {
self.state.close_write();
}
#[cfg(feature = "server")]
pub fn disable_keep_alive(&mut self) {
pub(crate) fn disable_keep_alive(&mut self) {
if self.state.is_idle() {
trace!("disable_keep_alive; closing idle connection");
self.state.close();
@@ -710,7 +710,7 @@ where
}
}
pub fn take_error(&mut self) -> crate::Result<()> {
pub(crate) fn take_error(&mut self) -> crate::Result<()> {
if let Some(err) = self.state.error.take() {
Err(err)
} else {

View File

@@ -17,7 +17,7 @@ use self::Kind::{Chunked, Eof, Length};
/// If a message body does not include a Transfer-Encoding, it *should*
/// include a Content-Length header.
#[derive(Clone, PartialEq)]
pub struct Decoder {
pub(crate) struct Decoder {
kind: Kind,
}
@@ -65,19 +65,19 @@ enum ChunkedState {
impl Decoder {
// constructors
pub fn length(x: u64) -> Decoder {
pub(crate) fn length(x: u64) -> Decoder {
Decoder {
kind: Kind::Length(x),
}
}
pub fn chunked() -> Decoder {
pub(crate) fn chunked() -> Decoder {
Decoder {
kind: Kind::Chunked(ChunkedState::Size, 0),
}
}
pub fn eof() -> Decoder {
pub(crate) fn eof() -> Decoder {
Decoder {
kind: Kind::Eof(false),
}
@@ -93,11 +93,11 @@ impl Decoder {
// methods
pub fn is_eof(&self) -> bool {
pub(crate) fn is_eof(&self) -> bool {
matches!(self.kind, Length(0) | Chunked(ChunkedState::End, _) | Eof(true))
}
pub fn decode<R: MemRead>(
pub(crate) fn decode<R: MemRead>(
&mut self,
cx: &mut task::Context<'_>,
body: &mut R,

View File

@@ -37,7 +37,7 @@ pub(crate) trait Dispatch {
cfg_server! {
use crate::service::HttpService;
pub struct Server<S: HttpService<B>, B> {
pub(crate) struct Server<S: HttpService<B>, B> {
in_flight: Pin<Box<Option<S::Future>>>,
pub(crate) service: S,
}
@@ -45,7 +45,7 @@ cfg_server! {
cfg_client! {
#[pin_project::pin_project]
pub struct Client<B> {
pub(crate) struct Client<B> {
callback: Option<crate::client::dispatch::Callback<Request<B>, http::Response<Body>>>,
#[pin]
rx: ClientRx<B>,
@@ -68,7 +68,7 @@ where
Bs: HttpBody + 'static,
Bs::Error: Into<Box<dyn StdError + Send + Sync>>,
{
pub fn new(dispatch: D, conn: Conn<I, Bs::Data, T>) -> Self {
pub(crate) fn new(dispatch: D, conn: Conn<I, Bs::Data, T>) -> Self {
Dispatcher {
conn,
dispatch,
@@ -79,14 +79,14 @@ where
}
#[cfg(feature = "server")]
pub fn disable_keep_alive(&mut self) {
pub(crate) fn disable_keep_alive(&mut self) {
self.conn.disable_keep_alive();
if self.conn.is_write_closed() {
self.close();
}
}
pub fn into_inner(self) -> (I, Bytes, D) {
pub(crate) fn into_inner(self) -> (I, Bytes, D) {
let (io, buf) = self.conn.into_inner();
(io, buf, self.dispatch)
}
@@ -454,14 +454,14 @@ cfg_server! {
where
S: HttpService<B>,
{
pub fn new(service: S) -> Server<S, B> {
pub(crate) fn new(service: S) -> Server<S, B> {
Server {
in_flight: Box::pin(None),
service,
}
}
pub fn into_service(self) -> S {
pub(crate) fn into_service(self) -> S {
self.service
}
}
@@ -538,7 +538,7 @@ cfg_server! {
cfg_client! {
impl<B> Client<B> {
pub fn new(rx: ClientRx<B>) -> Client<B> {
pub(crate) fn new(rx: ClientRx<B>) -> Client<B> {
Client {
callback: None,
rx,

View File

@@ -10,18 +10,18 @@ type StaticBuf = &'static [u8];
/// Encoders to handle different Transfer-Encodings.
#[derive(Debug, Clone, PartialEq)]
pub struct Encoder {
pub(crate) struct Encoder {
kind: Kind,
is_last: bool,
}
#[derive(Debug)]
pub struct EncodedBuf<B> {
pub(crate) struct EncodedBuf<B> {
kind: BufKind<B>,
}
#[derive(Debug)]
pub struct NotEof;
pub(crate) struct NotEof;
#[derive(Debug, PartialEq, Clone)]
enum Kind {
@@ -54,34 +54,34 @@ impl Encoder {
is_last: false,
}
}
pub fn chunked() -> Encoder {
pub(crate) fn chunked() -> Encoder {
Encoder::new(Kind::Chunked)
}
pub fn length(len: u64) -> Encoder {
pub(crate) fn length(len: u64) -> Encoder {
Encoder::new(Kind::Length(len))
}
#[cfg(feature = "server")]
pub fn close_delimited() -> Encoder {
pub(crate) fn close_delimited() -> Encoder {
Encoder::new(Kind::CloseDelimited)
}
pub fn is_eof(&self) -> bool {
pub(crate) fn is_eof(&self) -> bool {
matches!(self.kind, Kind::Length(0))
}
#[cfg(feature = "server")]
pub fn set_last(mut self, is_last: bool) -> Self {
pub(crate) fn set_last(mut self, is_last: bool) -> Self {
self.is_last = is_last;
self
}
pub fn is_last(&self) -> bool {
pub(crate) fn is_last(&self) -> bool {
self.is_last
}
pub fn is_close_delimited(&self) -> bool {
pub(crate) fn is_close_delimited(&self) -> bool {
match self.kind {
#[cfg(feature = "server")]
Kind::CloseDelimited => true,
@@ -89,7 +89,7 @@ impl Encoder {
}
}
pub fn end<B>(&self) -> Result<Option<EncodedBuf<B>>, NotEof> {
pub(crate) fn end<B>(&self) -> Result<Option<EncodedBuf<B>>, NotEof> {
match self.kind {
Kind::Length(0) => Ok(None),
Kind::Chunked => Ok(Some(EncodedBuf {
@@ -101,7 +101,7 @@ impl Encoder {
}
}
pub fn encode<B>(&mut self, msg: B) -> EncodedBuf<B>
pub(crate) fn encode<B>(&mut self, msg: B) -> EncodedBuf<B>
where
B: Buf,
{

View File

@@ -15,7 +15,7 @@ use crate::common::{task, Pin, Poll};
pub(crate) const INIT_BUFFER_SIZE: usize = 8192;
/// The minimum value that can be set to max buffer size.
pub const MINIMUM_MAX_BUFFER_SIZE: usize = INIT_BUFFER_SIZE;
pub(crate) const MINIMUM_MAX_BUFFER_SIZE: usize = INIT_BUFFER_SIZE;
/// The default maximum read buffer size. If the buffer gets this big and
/// a message is still not complete, a `TooLarge` error is triggered.
@@ -29,7 +29,7 @@ pub(crate) const DEFAULT_MAX_BUFFER_SIZE: usize = 8192 + 4096 * 100;
/// forces a flush if the queue gets this big.
const MAX_BUF_LIST_BUFFERS: usize = 16;
pub struct Buffered<T, B> {
pub(crate) struct Buffered<T, B> {
flush_pipeline: bool,
io: T,
read_blocked: bool,
@@ -55,7 +55,7 @@ where
T: AsyncRead + AsyncWrite + Unpin,
B: Buf,
{
pub fn new(io: T) -> Buffered<T, B> {
pub(crate) fn new(io: T) -> Buffered<T, B> {
let write_buf = WriteBuf::new(&io);
Buffered {
flush_pipeline: false,
@@ -68,7 +68,7 @@ where
}
#[cfg(feature = "server")]
pub fn set_flush_pipeline(&mut self, enabled: bool) {
pub(crate) fn set_flush_pipeline(&mut self, enabled: bool) {
debug_assert!(!self.write_buf.has_remaining());
self.flush_pipeline = enabled;
if enabled {
@@ -76,7 +76,7 @@ where
}
}
pub fn set_max_buf_size(&mut self, max: usize) {
pub(crate) fn set_max_buf_size(&mut self, max: usize) {
assert!(
max >= MINIMUM_MAX_BUFFER_SIZE,
"The max_buf_size cannot be smaller than {}.",
@@ -87,19 +87,19 @@ where
}
#[cfg(feature = "client")]
pub fn set_read_buf_exact_size(&mut self, sz: usize) {
pub(crate) fn set_read_buf_exact_size(&mut self, sz: usize) {
self.read_buf_strategy = ReadStrategy::Exact(sz);
}
#[cfg(feature = "server")]
pub fn set_write_strategy_flatten(&mut self) {
pub(crate) fn set_write_strategy_flatten(&mut self) {
// this should always be called only at construction time,
// so this assert is here to catch myself
debug_assert!(self.write_buf.queue.bufs_cnt() == 0);
self.write_buf.set_strategy(WriteStrategy::Flatten);
}
pub fn read_buf(&self) -> &[u8] {
pub(crate) fn read_buf(&self) -> &[u8] {
self.read_buf.as_ref()
}
@@ -115,7 +115,7 @@ where
self.read_buf.capacity() - self.read_buf.len()
}
pub fn headers_buf(&mut self) -> &mut Vec<u8> {
pub(crate) fn headers_buf(&mut self) -> &mut Vec<u8> {
let buf = self.write_buf.headers_mut();
&mut buf.bytes
}
@@ -124,15 +124,15 @@ where
&mut self.write_buf
}
pub fn buffer<BB: Buf + Into<B>>(&mut self, buf: BB) {
pub(crate) fn buffer<BB: Buf + Into<B>>(&mut self, buf: BB) {
self.write_buf.buffer(buf)
}
pub fn can_buffer(&self) -> bool {
pub(crate) fn can_buffer(&self) -> bool {
self.flush_pipeline || self.write_buf.can_buffer()
}
pub fn consume_leading_lines(&mut self) {
pub(crate) fn consume_leading_lines(&mut self) {
if !self.read_buf.is_empty() {
let mut i = 0;
while i < self.read_buf.len() {
@@ -182,7 +182,7 @@ where
}
}
pub fn poll_read_from_io(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<usize>> {
pub(crate) fn poll_read_from_io(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<usize>> {
self.read_blocked = false;
let next = self.read_buf_strategy.next();
if self.read_buf_remaining_mut() < next {
@@ -212,19 +212,19 @@ where
}
}
pub fn into_inner(self) -> (T, Bytes) {
pub(crate) fn into_inner(self) -> (T, Bytes) {
(self.io, self.read_buf.freeze())
}
pub fn io_mut(&mut self) -> &mut T {
pub(crate) fn io_mut(&mut self) -> &mut T {
&mut self.io
}
pub fn is_read_blocked(&self) -> bool {
pub(crate) fn is_read_blocked(&self) -> bool {
self.read_blocked
}
pub fn poll_flush(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
pub(crate) fn poll_flush(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
if self.flush_pipeline && !self.read_buf.is_empty() {
Poll::Ready(Ok(()))
} else if self.write_buf.remaining() == 0 {
@@ -293,7 +293,7 @@ where
impl<T: Unpin, B> Unpin for Buffered<T, B> {}
// TODO: This trait is old... at least rename to PollBytes or something...
pub trait MemRead {
pub(crate) trait MemRead {
fn read_mem(&mut self, cx: &mut task::Context<'_>, len: usize) -> Poll<io::Result<Bytes>>;
}
@@ -402,7 +402,7 @@ impl Default for ReadStrategy {
}
#[derive(Clone)]
pub struct Cursor<T> {
pub(crate) struct Cursor<T> {
bytes: T,
pos: usize,
}

View File

@@ -5,11 +5,11 @@ use crate::body::DecodedLength;
use crate::proto::{BodyLength, MessageHead};
pub(crate) use self::conn::Conn;
pub use self::decode::Decoder;
pub(crate) use self::decode::Decoder;
pub(crate) use self::dispatch::Dispatcher;
pub use self::encode::{EncodedBuf, Encoder};
pub use self::io::Cursor; //TODO: move out of h1::io
pub use self::io::MINIMUM_MAX_BUFFER_SIZE;
pub(crate) use self::encode::{EncodedBuf, Encoder};
//TODO: move out of h1::io
pub(crate) use self::io::MINIMUM_MAX_BUFFER_SIZE;
mod conn;
mod decode;

View File

@@ -136,7 +136,7 @@ where
}
}
pub fn graceful_shutdown(&mut self) {
pub(crate) fn graceful_shutdown(&mut self) {
trace!("graceful_shutdown");
match self.state {
State::Handshaking { .. } => {

View File

@@ -17,33 +17,33 @@ cfg_http2! {
/// An Incoming Message head. Includes request/status line, and headers.
#[derive(Debug, Default)]
pub struct MessageHead<S> {
pub(crate) struct MessageHead<S> {
/// HTTP version of the message.
pub version: http::Version,
pub(crate) version: http::Version,
/// Subject (request line or status line) of Incoming message.
pub subject: S,
pub(crate) subject: S,
/// Headers of the Incoming message.
pub headers: http::HeaderMap,
pub(crate) headers: http::HeaderMap,
/// Extensions.
extensions: http::Extensions,
}
/// An incoming request message.
#[cfg(feature = "http1")]
pub type RequestHead = MessageHead<RequestLine>;
pub(crate) type RequestHead = MessageHead<RequestLine>;
#[derive(Debug, Default, PartialEq)]
#[cfg(feature = "http1")]
pub struct RequestLine(pub http::Method, pub http::Uri);
pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri);
/// An incoming response message.
#[cfg(feature = "http1")]
#[cfg(feature = "client")]
pub type ResponseHead = MessageHead<http::StatusCode>;
pub(crate) type ResponseHead = MessageHead<http::StatusCode>;
#[derive(Debug)]
#[cfg(feature = "http1")]
pub enum BodyLength {
pub(crate) enum BodyLength {
/// Content-Length
Known(u64),
/// Transfer-Encoding: chunked (if h1)