Skip to content

Commit

Permalink
refactor(common): replace Never with Infallible (#3392)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Nov 6, 2023
1 parent 8e6095e commit a3c9fde
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/body/body.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::borrow::Cow;
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
use std::convert::Infallible;
#[cfg(feature = "stream")]
use std::error::Error as StdError;
use std::fmt;
Expand All @@ -19,8 +21,6 @@ use super::DecodedLength;
#[cfg(feature = "stream")]
use crate::common::sync_wrapper::SyncWrapper;
use crate::common::watch;
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
use crate::common::Never;
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
use crate::proto::h2::ping;

Expand Down Expand Up @@ -79,7 +79,7 @@ struct Extra {
}

#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
type DelayEofUntil = oneshot::Receiver<Never>;
type DelayEofUntil = oneshot::Receiver<Infallible>;

enum DelayEof {
/// Initial state, stream hasn't seen EOF yet.
Expand Down
8 changes: 4 additions & 4 deletions src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub mod http1;
#[cfg(all(feature = "backports", feature = "http2"))]
pub mod http2;

#[cfg(not(all(feature = "http1", feature = "http2")))]
use std::convert::Infallible;
use std::error::Error as StdError;
use std::fmt;
use std::future::Future;
Expand All @@ -82,8 +84,6 @@ use tracing::{debug, trace};
use super::dispatch;
use crate::body::HttpBody;
use crate::common::exec::{BoxSendFuture, Exec};
#[cfg(not(all(feature = "http1", feature = "http2")))]
use crate::common::Never;
use crate::proto;
use crate::rt::Executor;
#[cfg(feature = "http1")]
Expand All @@ -95,13 +95,13 @@ type Http1Dispatcher<T, B> =
proto::dispatch::Dispatcher<proto::dispatch::Client<B>, B, T, proto::h1::ClientTransaction>;

#[cfg(not(feature = "http1"))]
type Http1Dispatcher<T, B> = (Never, PhantomData<(T, Pin<Box<B>>)>);
type Http1Dispatcher<T, B> = (Infallible, PhantomData<(T, Pin<Box<B>>)>);

#[cfg(feature = "http2")]
type Http2ClientTask<B> = proto::h2::ClientTask<B>;

#[cfg(not(feature = "http2"))]
type Http2ClientTask<B> = (Never, PhantomData<Pin<Box<B>>>);
type Http2ClientTask<B> = (Infallible, PhantomData<Pin<Box<B>>>);

pin_project! {
#[project = ProtoClientProj]
Expand Down
4 changes: 2 additions & 2 deletions src/client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct PoolInner<T> {
// A oneshot channel is used to allow the interval to be notified when
// the Pool completely drops. That way, the interval can cancel immediately.
#[cfg(feature = "runtime")]
idle_interval_ref: Option<oneshot::Sender<crate::common::Never>>,
idle_interval_ref: Option<oneshot::Sender<std::convert::Infallible>>,
#[cfg(feature = "runtime")]
exec: Exec,
timeout: Option<Duration>,
Expand Down Expand Up @@ -741,7 +741,7 @@ pin_project_lite::pin_project! {
// Pool is fully dropped, and shutdown. This channel is never sent on,
// but Err(Canceled) will be received when the Pool is dropped.
#[pin]
pool_drop_notifier: oneshot::Receiver<crate::common::Never>,
pool_drop_notifier: oneshot::Receiver<std::convert::Infallible>,
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub(crate) mod exec;
pub(crate) mod io;
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
mod lazy;
mod never;
#[cfg(any(
feature = "stream",
all(feature = "client", any(feature = "http1", feature = "http2"))
Expand All @@ -29,5 +28,3 @@ pub(crate) mod watch;

#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
pub(crate) use self::lazy::{lazy, Started as Lazy};
#[cfg(any(feature = "http1", feature = "http2", feature = "runtime"))]
pub(crate) use self::never::Never;
21 changes: 0 additions & 21 deletions src/common/never.rs

This file was deleted.

9 changes: 5 additions & 4 deletions src/common/task.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::task::{Context, Poll};

use super::Never;
use std::{
convert::Infallible,
task::{Context, Poll},
};

/// A function to help "yield" a future, such that it is re-scheduled immediately.
///
/// Useful for spin counts, so a future doesn't hog too much time.
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<Never> {
pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll<Infallible> {
cx.waker().wake_by_ref();
Poll::Pending
}
4 changes: 2 additions & 2 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,13 @@ cfg_client! {
{
type PollItem = RequestHead;
type PollBody = B;
type PollError = crate::common::Never;
type PollError = std::convert::Infallible;
type RecvItem = crate::proto::ResponseHead;

fn poll_msg(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), crate::common::Never>>> {
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), Self::PollError>>> {
let mut this = self.as_mut();
debug_assert!(!this.rx_closed);
match this.rx.poll_recv(cx) {
Expand Down
9 changes: 5 additions & 4 deletions src/proto/h2/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::Infallible;
use std::error::Error as StdError;
use std::future::Future;
use std::marker::Unpin;
Expand All @@ -19,7 +20,7 @@ use tracing::{debug, trace, warn};
use super::{ping, H2Upgraded, PipeToSendStream, SendBuf};
use crate::body::HttpBody;
use crate::client::dispatch::Callback;
use crate::common::{exec::Exec, Never};
use crate::common::exec::Exec;
use crate::ext::Protocol;
use crate::headers;
use crate::proto::h2::UpgradedSendStream;
Expand All @@ -32,11 +33,11 @@ type ClientRx<B> = crate::client::dispatch::Receiver<Request<B>, Response<Body>>

///// An mpsc channel is used to help notify the `Connection` task when *all*
///// other handles to it have been dropped, so that it can shutdown.
type ConnDropRef = mpsc::Sender<Never>;
type ConnDropRef = mpsc::Sender<Infallible>;

///// A oneshot channel watches the `Connection` task, and when it completes,
///// the "dispatch" task will be notified and can shutdown sooner.
type ConnEof = oneshot::Receiver<Never>;
type ConnEof = oneshot::Receiver<Infallible>;

// Our defaults are chosen for the "majority" case, which usually are not
// resource constrained, and so the spec default of 64kb can be too limiting
Expand Down Expand Up @@ -181,7 +182,7 @@ where
})
}

async fn conn_task<C, D>(conn: C, drop_rx: D, cancel_tx: oneshot::Sender<Never>)
async fn conn_task<C, D>(conn: C, drop_rx: D, cancel_tx: oneshot::Sender<Infallible>)
where
C: Future + Unpin,
D: Future<Output = ()> + Unpin,
Expand Down
8 changes: 4 additions & 4 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ cfg_feature! {
use std::pin::Pin;
use std::future::Future;
use std::marker::Unpin;
#[cfg(not(all(feature = "http1", feature = "http2")))]
use std::convert::Infallible;

use bytes::Bytes;
use pin_project_lite::pin_project;
Expand All @@ -80,8 +82,6 @@ cfg_feature! {

pub use super::server::Connecting;
use crate::body::{Body, HttpBody};
#[cfg(not(all(feature = "http1", feature = "http2")))]
use crate::common::Never;
use crate::common::exec::{ConnStreamExec, Exec};
use crate::proto;
use crate::service::HttpService;
Expand Down Expand Up @@ -159,14 +159,14 @@ type Http1Dispatcher<T, B, S> =
proto::h1::Dispatcher<proto::h1::dispatch::Server<S, Body>, B, T, proto::ServerTransaction>;

#[cfg(all(not(feature = "http1"), feature = "http2"))]
type Http1Dispatcher<T, B, S> = (Never, PhantomData<(T, Box<Pin<B>>, Box<Pin<S>>)>);
type Http1Dispatcher<T, B, S> = (Infallible, PhantomData<(T, Box<Pin<B>>, Box<Pin<S>>)>);

#[cfg(feature = "http2")]
type Http2Server<T, B, S, E> = proto::h2::Server<Rewind<T>, S, B, E>;

#[cfg(all(not(feature = "http2"), feature = "http1"))]
type Http2Server<T, B, S, E> = (
Never,
Infallible,
PhantomData<(T, Box<Pin<S>>, Box<Pin<B>>, Box<Pin<E>>)>,
);

Expand Down

0 comments on commit a3c9fde

Please sign in to comment.