Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch crate::never::Never with futures::never::Never #298

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/sse.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::time::Duration;
use std::convert::Infallible;
use tokio::{clock::now, timer::Interval};
use futures::{never::Never, StreamExt};
use futures::StreamExt;
use warp::{Filter, sse::ServerSentEvent};

// create server-sent event
fn sse_counter(counter: u64) -> Result<impl ServerSentEvent, Never> {
fn sse_counter(counter: u64) -> Result<impl ServerSentEvent, Infallible> {
Ok(warp::sse::data(counter))
}

Expand Down
9 changes: 4 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::error::Error as StdError;
use std::convert::Infallible;
use std::fmt;
use std::io;

use hyper::Error as HyperError;
#[cfg(feature = "websocket")]
use tungstenite::Error as WsError;

use crate::never::Never;

/// Errors that can happen inside warp.
pub struct Error(Box<Kind>);

Expand Down Expand Up @@ -66,9 +65,9 @@ impl From<Kind> for Error {
}
}

impl From<Never> for Error {
fn from(never: Never) -> Error {
match never {}
impl From<Infallible> for Error {
fn from(infallible: Infallible) -> Error {
match infallible {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/filters/addr.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Socket Address filters.

use std::net::SocketAddr;
use std::convert::Infallible;

use crate::filter::{filter_fn_one, Filter};
use crate::never::Never;

/// Creates a `Filter` to get the remote address of the connection.
///
Expand All @@ -21,6 +21,6 @@ use crate::never::Never;
/// println!("remote address = {:?}", addr);
/// });
/// ```
pub fn remote() -> impl Filter<Extract = (Option<SocketAddr>,), Error = Never> + Copy {
pub fn remote() -> impl Filter<Extract = (Option<SocketAddr>,), Error = Infallible> + Copy {
filter_fn_one(|route| futures::future::ok(route.remote_addr()))
}
8 changes: 4 additions & 4 deletions src/filters/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use std::pin::Pin;
use std::task::{Context, Poll};
use std::future::Future;
use std::convert::Infallible;

use crate::filter::{Filter, FilterBase};
use crate::never::Never;

/// A filter that matches any route.
///
Expand Down Expand Up @@ -44,7 +44,7 @@ use crate::never::Never;
/// db.contains(&param_id)
/// });
/// ```
pub fn any() -> impl Filter<Extract = (), Error = Never> + Copy {
pub fn any() -> impl Filter<Extract = (), Error = Infallible> + Copy {
Any
}

Expand All @@ -54,7 +54,7 @@ struct Any;

impl FilterBase for Any {
type Extract = ();
type Error = Never;
type Error = Infallible;
type Future = AnyFut;

#[inline]
Expand All @@ -67,7 +67,7 @@ impl FilterBase for Any {
struct AnyFut;

impl Future for AnyFut {
type Output = Result<(), Never>;
type Output = Result<(), Infallible>;

#[inline]
fn poll(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Self::Output> {
Expand Down
6 changes: 3 additions & 3 deletions src/filters/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use headers::Cookie;
use futures::future;

use super::header;
use std::convert::Infallible;
use crate::filter::{filter_fn_one, Filter, One};
use crate::never::Never;
use crate::reject::Rejection;

/// Creates a `Filter` that requires a cookie by name.
Expand All @@ -27,7 +27,7 @@ pub fn cookie(name: &'static str) -> impl Filter<Extract = One<String>, Error =
/// the request, extracting `None`.
pub fn optional(
name: &'static str,
) -> impl Filter<Extract = One<Option<String>>, Error = Never> + Copy {
) -> impl Filter<Extract = One<Option<String>>, Error = Infallible> + Copy {
header::optional2()
.map(move |opt: Option<Cookie>| opt.and_then(|cookie| cookie.get(name).map(String::from)))
}
Expand All @@ -37,7 +37,7 @@ pub fn optional(
pub fn optional_value<U, F>(
name: &'static str,
func: F,
) -> impl Filter<Extract = One<Option<U>>, Error = Never> + Copy
) -> impl Filter<Extract = One<Option<U>>, Error = Infallible> + Copy
where
F: Fn(&str) -> U + Copy,
U: Send + 'static,
Expand Down
4 changes: 2 additions & 2 deletions src/filters/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::sync::Arc;
use std::pin::Pin;
use std::future::Future;
use std::task::Poll;
use std::convert::Infallible;

use bytes::{BufMut, BytesMut};
use futures::future::Either;
Expand All @@ -24,7 +25,6 @@ use tokio::io::AsyncRead;
use urlencoding::decode;

use crate::filter::{Filter, FilterClone, One};
use crate::never::Never;
use crate::reject::{self, Rejection};
use crate::reply::{Reply, Response};

Expand Down Expand Up @@ -206,7 +206,7 @@ impl Conditionals {
}
}

fn conditionals() -> impl Filter<Extract = One<Conditionals>, Error = Never> + Copy {
fn conditionals() -> impl Filter<Extract = One<Conditionals>, Error = Infallible> + Copy {
crate::header::optional2()
.and(crate::header::optional2())
.and(crate::header::optional2())
Expand Down
6 changes: 3 additions & 3 deletions src/filters/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
//! they don't extract any values. The `header` filter allows parsing
//! a type from any header.
use std::str::FromStr;
use std::convert::Infallible;

use headers::{Header, HeaderMapExt};
use http::HeaderMap;
use futures::future;

use crate::filter::{filter_fn, filter_fn_one, Filter, One};
use crate::never::Never;
use crate::reject::{self, Rejection};

/// Create a `Filter` that tries to parse the specified header.
Expand Down Expand Up @@ -96,7 +96,7 @@ where
})
}

pub(crate) fn optional2<T>() -> impl Filter<Extract = One<Option<T>>, Error = Never> + Copy
pub(crate) fn optional2<T>() -> impl Filter<Extract = One<Option<T>>, Error = Infallible> + Copy
where
T: Header + Send + 'static,
{
Expand Down Expand Up @@ -198,6 +198,6 @@ pub fn exact_ignore_case(
/// format!("header count: {}", headers.len())
/// });
/// ```
pub fn headers_cloned() -> impl Filter<Extract = One<HeaderMap>, Error = Never> + Copy {
pub fn headers_cloned() -> impl Filter<Extract = One<HeaderMap>, Error = Infallible> + Copy {
filter_fn_one(|route| future::ok(route.headers().clone()))
}
6 changes: 3 additions & 3 deletions src/filters/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use http::Method;
use futures::future;

use std::convert::Infallible;
use crate::filter::{filter_fn, filter_fn_one, Filter, One};
use crate::never::Never;
use crate::reject::{Rejection};

/// Create a `Filter` that requires the request method to be `GET`.
Expand Down Expand Up @@ -118,8 +118,8 @@ pub fn patch() -> impl Filter<Extract = (), Error = Rejection> + Copy {
/// format!("You sent a {} request!", method)
/// });
/// ```
pub fn method() -> impl Filter<Extract = One<Method>, Error = Never> + Copy {
filter_fn_one(|route| future::ok::<_, Never>(route.method().clone()))
pub fn method() -> impl Filter<Extract = One<Method>, Error = Infallible> + Copy {
filter_fn_one(|route| future::ok::<_, Infallible>(route.method().clone()))
}

// NOTE: This takes a static function instead of `&'static Method` directly
Expand Down
8 changes: 4 additions & 4 deletions src/filters/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@

use std::fmt;
use std::str::FromStr;
use std::convert::Infallible;

use http::uri::PathAndQuery;
use futures::future;

use crate::filter::{filter_fn, one, Filter, One, Tuple};
use crate::never::Never;
use crate::reject::{self, Rejection};
use crate::route::Route;

Expand Down Expand Up @@ -291,7 +291,7 @@ where
/// format!("The tail after foo is {:?}", tail)
/// });
/// ```
pub fn tail() -> impl Filter<Extract = One<Tail>, Error = Never> + Copy {
pub fn tail() -> impl Filter<Extract = One<Tail>, Error = Infallible> + Copy {
filter_fn(move |route| {
let path = path_and_query(&route);
let idx = route.matched_path_index();
Expand Down Expand Up @@ -345,7 +345,7 @@ impl fmt::Debug for Tail {
/// format!("The path after foo is {:?}", peek)
/// });
/// ```
pub fn peek() -> impl Filter<Extract = One<Peek>, Error = Never> + Copy {
pub fn peek() -> impl Filter<Extract = One<Peek>, Error = Infallible> + Copy {
filter_fn(move |route| {
let path = path_and_query(&route);
let idx = route.matched_path_index();
Expand Down Expand Up @@ -412,7 +412,7 @@ impl fmt::Debug for Peek {
/// format!("This is the {}th visit to this URL!", count)
/// });
/// ```
pub fn full() -> impl Filter<Extract = One<FullPath>, Error = Never> + Copy {
pub fn full() -> impl Filter<Extract = One<FullPath>, Error = Infallible> + Copy {
filter_fn(move |route| future::ok(one(FullPath(path_and_query(&route)))))
}

Expand Down
13 changes: 7 additions & 6 deletions src/filters/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
//! ```
//!
//! use std::time::Duration;
//! use std::convert::Infallible;
//! use warp::{Filter, sse::ServerSentEvent};
//! use futures::{stream::iter, Stream};
//! use futures::never::Never;
//!
//! fn sse_events() -> impl Stream<Item = Result<impl ServerSentEvent,Never>> {
//! fn sse_events() -> impl Stream<Item = Result<impl ServerSentEvent, Infallible>> {
//! iter(vec![
//! Ok(warp::sse::data("unnamed event").into_a()),
//! Ok((
Expand Down Expand Up @@ -362,7 +362,7 @@ impl Sse {
/// use std::time::Duration;
/// use futures::Stream;
/// use futures::stream::iter;
/// use futures::never::Never;
/// use std::convert::Infallible;
/// use warp::{Filter, sse::ServerSentEvent};
/// use serde_derive::Serialize;
///
Expand All @@ -372,7 +372,7 @@ impl Sse {
/// text: String,
/// }
///
/// fn event_stream() -> impl Stream<Item = Result<impl ServerSentEvent, Never>> {
/// fn event_stream() -> impl Stream<Item = Result<impl ServerSentEvent, Infallible>> {
/// iter(vec![
/// // Unnamed event with data only
/// Ok(warp::sse::data("payload").boxed()),
Expand Down Expand Up @@ -572,12 +572,13 @@ where
///
/// ```
/// use std::time::Duration;
/// use futures::{never::Never, StreamExt};
/// use std::convert::Infallible;
/// use futures::StreamExt;
/// use tokio::{clock::now, timer::Interval};
/// use warp::{Filter, Stream, sse::ServerSentEvent};
///
/// // create server-sent event
/// fn sse_counter(counter: u64) -> Result<impl ServerSentEvent, Never> {
/// fn sse_counter(counter: u64) -> Result<impl ServerSentEvent, Infallible> {
/// Ok(warp::sse::data(counter))
/// }
///
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ mod error;
mod filter;
pub mod filters;
mod generic;
mod never;
pub mod redirect;
pub mod reject;
pub mod reply;
Expand Down
17 changes: 0 additions & 17 deletions src/never.rs

This file was deleted.

25 changes: 12 additions & 13 deletions src/reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use std::error::Error as StdError;
use std::fmt;
use std::convert::Infallible;

use http::{
self,
Expand All @@ -39,8 +40,6 @@ use hyper::Body;
use serde;
use serde_json;

use crate::never::Never;

pub(crate) use self::sealed::{CombineRejection, Reject};

//TODO(v0.2): This should just be `type Cause = StdError + Send + Sync + 'static`,
Expand Down Expand Up @@ -301,14 +300,14 @@ impl Rejection {
}
}

impl From<Never> for Rejection {
impl From<Infallible> for Rejection {
#[inline]
fn from(never: Never) -> Rejection {
match never {}
fn from(infallible: Infallible) -> Rejection {
match infallible {}
}
}

impl Reject for Never {
impl Reject for Infallible {
fn status(&self) -> StatusCode {
match *self {}
}
Expand Down Expand Up @@ -654,8 +653,8 @@ trait Typed: StdError + 'static {

mod sealed {
use super::{Cause, Reason, Rejection, Rejections};
use crate::never::Never;
use http::StatusCode;
use std::convert::Infallible;
use std::fmt;

pub trait Reject: fmt::Debug + Send + Sync {
Expand Down Expand Up @@ -696,26 +695,26 @@ mod sealed {
}
}

impl CombineRejection<Never> for Rejection {
impl CombineRejection<Infallible> for Rejection {
type Rejection = Rejection;

fn combine(self, other: Never) -> Self::Rejection {
fn combine(self, other: Infallible) -> Self::Rejection {
match other {}
}
}

impl CombineRejection<Rejection> for Never {
impl CombineRejection<Rejection> for Infallible {
type Rejection = Rejection;

fn combine(self, _: Rejection) -> Self::Rejection {
match self {}
}
}

impl CombineRejection<Never> for Never {
type Rejection = Never;
impl CombineRejection<Infallible > for Infallible {
type Rejection = Infallible ;

fn combine(self, _: Never) -> Self::Rejection {
fn combine(self, _: Infallible) -> Self::Rejection {
match self {}
}
}
Expand Down
Loading