Skip to content

Commit

Permalink
refactor(common): replace Never with Infallible (#3335)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Oct 4, 2023
1 parent e8e059e commit 5a8f4c0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 39 deletions.
3 changes: 0 additions & 3 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ pub(crate) mod date;
#[cfg(not(feature = "http2"))]
pub(crate) mod exec;
pub(crate) mod io;
mod never;
pub(crate) mod task;
#[cfg(any(feature = "http1", feature = "http2", feature = "server"))]
pub(crate) mod time;
pub(crate) mod watch;

#[cfg(any(feature = "http1", feature = "http2"))]
pub(crate) use self::never::Never;
pub(crate) use self::task::Poll;

// group up types normally needed for `Future`
Expand Down
21 changes: 0 additions & 21 deletions src/common/never.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/common/task.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[cfg(feature = "http1")]
use super::Never;
use std::convert::Infallible;
pub(crate) use std::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.
#[cfg(feature = "http1")]
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
}
6 changes: 4 additions & 2 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ cfg_server! {
// ===== impl Client =====

cfg_client! {
use std::convert::Infallible;

impl<B> Client<B> {
pub(crate) fn new(rx: ClientRx<B>) -> Client<B> {
Client {
Expand All @@ -565,13 +567,13 @@ cfg_client! {
{
type PollItem = RequestHead;
type PollBody = B;
type PollError = crate::common::Never;
type PollError = Infallible;
type RecvItem = crate::proto::ResponseHead;

fn poll_msg(
mut self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), crate::common::Never>>> {
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), Infallible>>> {
let mut this = self.as_mut();
debug_assert!(!this.rx_closed);
match this.rx.poll_recv(cx) {
Expand Down
20 changes: 9 additions & 11 deletions src/proto/h2/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::marker::PhantomData;

use std::time::Duration;
use std::{convert::Infallible, marker::PhantomData, time::Duration};

use crate::rt::{Read, Write};
use bytes::Bytes;
Expand All @@ -19,7 +17,7 @@ use crate::body::{Body, Incoming as IncomingBody};
use crate::client::dispatch::{Callback, SendWhen};
use crate::common::io::Compat;
use crate::common::time::Time;
use crate::common::{task, Future, Never, Pin, Poll};
use crate::common::{task, Future, Pin, Poll};
use crate::ext::Protocol;
use crate::headers;
use crate::proto::h2::UpgradedSendStream;
Expand All @@ -33,11 +31,11 @@ type ClientRx<B> = crate::client::dispatch::Receiver<Request<B>, Response<Incomi

///// 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 @@ -267,9 +265,9 @@ pin_project! {
T: Unpin,
{
#[pin]
drop_rx: StreamFuture<Receiver<Never>>,
drop_rx: StreamFuture<Receiver<Infallible>>,
#[pin]
cancel_tx: Option<oneshot::Sender<Never>>,
cancel_tx: Option<oneshot::Sender<Infallible>>,
#[pin]
conn: ConnMapErr<T, B>,
}
Expand All @@ -282,8 +280,8 @@ where
{
fn new(
conn: ConnMapErr<T, B>,
drop_rx: StreamFuture<Receiver<Never>>,
cancel_tx: oneshot::Sender<Never>,
drop_rx: StreamFuture<Receiver<Infallible>>,
cancel_tx: oneshot::Sender<Infallible>,
) -> Self {
Self {
drop_rx,
Expand Down Expand Up @@ -421,7 +419,7 @@ pin_project! {
#[pin]
pipe: PipeToSendStream<S>,
#[pin]
conn_drop_ref: Option<Sender<Never>>,
conn_drop_ref: Option<Sender<Infallible>>,
#[pin]
ping: Option<Recorder>,
}
Expand Down

0 comments on commit 5a8f4c0

Please sign in to comment.