1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-23 04:52:28 +00:00

remove FromBodyNoError and replace with std::convert::Infallible

This commit is contained in:
Dominic 2020-05-05 23:08:57 +02:00
parent 4cd2474d90
commit 52679ad29d
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 7 additions and 13 deletions

View file

@ -1,5 +1,5 @@
use super::{IntoResponseError, ResourceResult, handle_error}; use super::{IntoResponseError, ResourceResult, handle_error};
use crate::{FromBody, FromBodyNoError, RequestBody, ResourceType, Response, StatusCode}; use crate::{FromBody, RequestBody, ResourceType, Response, StatusCode};
#[cfg(feature = "openapi")] #[cfg(feature = "openapi")]
use crate::OpenapiSchema; use crate::OpenapiSchema;
use futures_core::future::Future; use futures_core::future::Future;
@ -10,6 +10,7 @@ use mime::Mime;
use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty}; use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty};
use serde_json::error::Error as SerdeJsonError; use serde_json::error::Error as SerdeJsonError;
use std::{ use std::{
convert::Infallible,
fmt::Display, fmt::Display,
pin::Pin pin::Pin
}; };
@ -89,7 +90,7 @@ impl<T : Clone> Clone for Raw<T>
impl<T : for<'a> From<&'a [u8]>> FromBody for Raw<T> impl<T : for<'a> From<&'a [u8]>> FromBody for Raw<T>
{ {
type Err = FromBodyNoError; type Err = Infallible;
fn from_body(body : Bytes, mime : Mime) -> Result<Self, Self::Err> fn from_body(body : Bytes, mime : Mime) -> Result<Self, Self::Err>
{ {

View file

@ -8,7 +8,6 @@ use std::{
error::Error, error::Error,
panic::RefUnwindSafe panic::RefUnwindSafe
}; };
use thiserror::Error;
#[cfg(not(feature = "openapi"))] #[cfg(not(feature = "openapi"))]
pub trait ResourceType pub trait ResourceType
@ -68,8 +67,8 @@ struct RawImage {
pub trait FromBody : Sized pub trait FromBody : Sized
{ {
/// The error type returned by the conversion if it was unsuccessfull. When using the derive /// The error type returned by the conversion if it was unsuccessfull. When using the derive
/// macro, there is no way to trigger an error, so /// macro, there is no way to trigger an error, so `Infallible` is used here. However, this
/// [`FromBodyNoError`](struct.FromBodyNoError.html) is used here. /// might change in the future.
type Err : Error; type Err : Error;
/// Perform the conversion. /// Perform the conversion.
@ -86,12 +85,6 @@ impl<T : DeserializeOwned> FromBody for T
} }
} }
/// This error type can be used by [`FromBody`](trait.FromBody.html) implementations when there
/// is no need to return any errors.
#[derive(Clone, Copy, Debug, Error)]
#[error("No Error")]
pub struct FromBodyNoError;
/** /**
A type that can be used inside a request body. Implemented for every type that is deserializable A type that can be used inside a request body. Implemented for every type that is deserializable

View file

@ -120,9 +120,9 @@ pub fn expand_from_body(input : DeriveInput) -> Result<TokenStream>
impl #generics #krate::FromBody for #ident #generics impl #generics #krate::FromBody for #ident #generics
where #where_clause where #where_clause
{ {
type Err = #krate::FromBodyNoError; type Err = ::std::convert::Infallible;
fn from_body(#body_ident : #krate::gotham::hyper::body::Bytes, #type_ident : #krate::Mime) -> Result<Self, #krate::FromBodyNoError> fn from_body(#body_ident : #krate::gotham::hyper::body::Bytes, #type_ident : #krate::Mime) -> Result<Self, ::std::convert::Infallible>
{ {
#block #block
Ok(#ctor) Ok(#ctor)