Remove useless Responder::Error

This commit is contained in:
Nikolay Kim 2022-12-27 19:01:11 +01:00
parent 5fd0cd4713
commit 179608913c
9 changed files with 13 additions and 33 deletions

View file

@ -1,5 +1,13 @@
# Changes
## [0.6.0-alpha.0] - 2022-12-xx
* Upgrade to ntex-service 0.4
* web: Refactor FromRequest trait, allow to borrow from request
* web: Remove useless Responder::Error
## [0.5.31] - 2022-11-30
* http: Don't require mutable self reference in `Response::extensions_mut()` method

View file

@ -37,10 +37,10 @@ where
}
pub(super) trait HandlerFn<Err: ErrorRenderer> {
fn call<'a>(
&'a self,
fn call(
&self,
_: WebRequest<Err>,
) -> BoxFuture<'a, Result<WebResponse, Err::Container>>;
) -> BoxFuture<'_, Result<WebResponse, Err::Container>>;
}
pub(super) struct HandlerWrapper<F, T, Err> {
@ -62,7 +62,6 @@ where
F: Handler<T, Err> + 'static,
T: FromRequest<Err> + 'static,
T::Error: Into<Err::Container>,
<F::Output as Responder<Err>>::Error: Into<Err::Container>,
Err: ErrorRenderer,
{
fn call(

View file

@ -13,7 +13,6 @@ use super::dev::{insert_slash, WebServiceConfig, WebServiceFactory};
use super::extract::FromRequest;
use super::handler::Handler;
use super::request::WebRequest;
use super::responder::Responder;
use super::response::WebResponse;
use super::route::{IntoRoutes, Route, RouteService};
use super::{app::Filter, error::ErrorRenderer, guard::Guard, service::AppState};
@ -225,7 +224,6 @@ where
F: Handler<Args, Err> + 'static,
Args: FromRequest<Err> + 'static,
Args::Error: Into<Err::Container>,
<F::Output as Responder<Err>>::Error: Into<Err::Container>,
{
self.routes.push(Route::new().to(handler));
self

View file

@ -34,9 +34,6 @@ impl<T> Future for Ready<T> {
///
/// Types that implement this trait can be used as the return type of a handler.
pub trait Responder<Err = DefaultError> {
/// The associated error which can be returned.
type Error;
/// The future response value.
type Future: Future<Output = Response>;
@ -93,7 +90,6 @@ pub trait Responder<Err = DefaultError> {
}
impl<Err: ErrorRenderer> Responder<Err> for Response {
type Error = Err::Container;
type Future = Ready<Response>;
#[inline]
@ -103,7 +99,6 @@ impl<Err: ErrorRenderer> Responder<Err> for Response {
}
impl<Err: ErrorRenderer> Responder<Err> for ResponseBuilder {
type Error = Err::Container;
type Future = Ready<Response>;
#[inline]
@ -117,7 +112,6 @@ where
T: Responder<Err>,
Err: ErrorRenderer,
{
type Error = T::Error;
type Future = Either<T::Future, Ready<Response>>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {
@ -136,7 +130,6 @@ where
E: Into<Err::Container>,
Err: ErrorRenderer,
{
type Error = T::Error;
type Future = Either<T::Future, Ready<Response>>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {
@ -152,7 +145,6 @@ where
T: Responder<Err>,
Err: ErrorRenderer,
{
type Error = T::Error;
type Future = CustomResponderFut<T, Err>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {
@ -165,7 +157,6 @@ where
}
impl<Err: ErrorRenderer> Responder<Err> for &'static str {
type Error = Err::Container;
type Future = Ready<Response>;
fn respond_to(self, _: &HttpRequest) -> Self::Future {
@ -178,7 +169,6 @@ impl<Err: ErrorRenderer> Responder<Err> for &'static str {
}
impl<Err: ErrorRenderer> Responder<Err> for &'static [u8] {
type Error = Err::Container;
type Future = Ready<Response>;
fn respond_to(self, _: &HttpRequest) -> Self::Future {
@ -191,7 +181,6 @@ impl<Err: ErrorRenderer> Responder<Err> for &'static [u8] {
}
impl<Err: ErrorRenderer> Responder<Err> for String {
type Error = Err::Container;
type Future = Ready<Response>;
fn respond_to(self, _: &HttpRequest) -> Self::Future {
@ -204,7 +193,6 @@ impl<Err: ErrorRenderer> Responder<Err> for String {
}
impl<'a, Err: ErrorRenderer> Responder<Err> for &'a String {
type Error = Err::Container;
type Future = Ready<Response>;
fn respond_to(self, _: &HttpRequest) -> Self::Future {
@ -217,7 +205,6 @@ impl<'a, Err: ErrorRenderer> Responder<Err> for &'a String {
}
impl<Err: ErrorRenderer> Responder<Err> for Bytes {
type Error = Err::Container;
type Future = Ready<Response>;
fn respond_to(self, _: &HttpRequest) -> Self::Future {
@ -230,7 +217,6 @@ impl<Err: ErrorRenderer> Responder<Err> for Bytes {
}
impl<Err: ErrorRenderer> Responder<Err> for BytesMut {
type Error = Err::Container;
type Future = Ready<Response>;
fn respond_to(self, _: &HttpRequest) -> Self::Future {
@ -322,7 +308,6 @@ impl<T: Responder<Err>, Err> CustomResponder<T, Err> {
}
impl<T: Responder<Err>, Err: ErrorRenderer> Responder<Err> for CustomResponder<T, Err> {
type Error = T::Error;
type Future = CustomResponderFut<T, Err>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {
@ -390,7 +375,6 @@ where
B: Responder<Err>,
Err: ErrorRenderer,
{
type Error = Err::Container;
type Future = Either<A::Future, B::Future>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {
@ -406,7 +390,6 @@ where
T: std::fmt::Debug + std::fmt::Display + 'static,
Err: ErrorRenderer,
{
type Error = Err::Container;
type Future = Ready<Response>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {
@ -423,9 +406,7 @@ pub(crate) mod tests {
use crate::web::test::{init_service, TestRequest};
use crate::{service::Service, util::Bytes, util::BytesMut, web};
fn responder<T: Responder<DefaultError>>(
responder: T,
) -> impl Responder<DefaultError, Error = T::Error> {
fn responder<T: Responder<DefaultError>>(responder: T) -> impl Responder<DefaultError> {
responder
}

View file

@ -9,7 +9,6 @@ use super::extract::FromRequest;
use super::guard::{self, Guard};
use super::handler::{Handler, HandlerFn, HandlerWrapper};
use super::request::WebRequest;
use super::responder::Responder;
use super::response::WebResponse;
use super::HttpResponse;
@ -184,7 +183,6 @@ impl<Err: ErrorRenderer> Route<Err> {
F: Handler<Args, Err> + 'static,
Args: FromRequest<Err> + 'static,
Args::Error: Into<Err::Container>,
<F::Output as Responder<Err>>::Error: Into<Err::Container>,
{
self.handler = Rc::new(HandlerWrapper::new(handler));
self

View file

@ -300,7 +300,7 @@ where
/// WebServiceFactory implementation for a Vec<T>
#[allow(unused_parens)]
impl<Err, T> WebServiceFactory<Err> for Vec<T>
impl<T, Err> WebServiceFactory<Err> for Vec<T>
where
Err: ErrorRenderer,
T: WebServiceFactory<Err> + 'static,

View file

@ -136,7 +136,6 @@ impl<T: Serialize, Err: ErrorRenderer> Responder<Err> for Form<T>
where
Err::Container: From<serde_urlencoded::ser::Error>,
{
type Error = serde_urlencoded::ser::Error;
type Future = Ready<Response>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {

View file

@ -112,7 +112,6 @@ impl<T: Serialize, Err: ErrorRenderer> Responder<Err> for Json<T>
where
Err::Container: From<JsonError>,
{
type Error = JsonError;
type Future = Ready<Response>;
fn respond_to(self, req: &HttpRequest) -> Self::Future {

View file

@ -14,7 +14,6 @@ use super::error::ErrorRenderer;
use super::extract::FromRequest;
use super::handler::Handler;
use super::resource::Resource;
use super::responder::Responder;
use super::route::Route;
use super::scope::Scope;
use super::server::HttpServer;
@ -229,7 +228,6 @@ where
Args: FromRequest<Err> + 'static,
Err: ErrorRenderer,
Err::Container: From<Args::Error>,
<F::Output as Responder<Err>>::Error: Into<Err::Container>,
{
Route::new().to(handler)
}