From 52679ad29db63e5e1bf51a44aa431ebf5d228ec4 Mon Sep 17 00:00:00 2001 From: Dominic Date: Tue, 5 May 2020 23:08:57 +0200 Subject: [PATCH] remove FromBodyNoError and replace with std::convert::Infallible --- gotham_restful/src/result/raw.rs | 5 +++-- gotham_restful/src/types.rs | 11 ++--------- gotham_restful_derive/src/from_body.rs | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/gotham_restful/src/result/raw.rs b/gotham_restful/src/result/raw.rs index ec3c848..a44e15a 100644 --- a/gotham_restful/src/result/raw.rs +++ b/gotham_restful/src/result/raw.rs @@ -1,5 +1,5 @@ use super::{IntoResponseError, ResourceResult, handle_error}; -use crate::{FromBody, FromBodyNoError, RequestBody, ResourceType, Response, StatusCode}; +use crate::{FromBody, RequestBody, ResourceType, Response, StatusCode}; #[cfg(feature = "openapi")] use crate::OpenapiSchema; use futures_core::future::Future; @@ -10,6 +10,7 @@ use mime::Mime; use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty}; use serde_json::error::Error as SerdeJsonError; use std::{ + convert::Infallible, fmt::Display, pin::Pin }; @@ -89,7 +90,7 @@ impl Clone for Raw impl From<&'a [u8]>> FromBody for Raw { - type Err = FromBodyNoError; + type Err = Infallible; fn from_body(body : Bytes, mime : Mime) -> Result { diff --git a/gotham_restful/src/types.rs b/gotham_restful/src/types.rs index c858d3b..576f7e9 100644 --- a/gotham_restful/src/types.rs +++ b/gotham_restful/src/types.rs @@ -8,7 +8,6 @@ use std::{ error::Error, panic::RefUnwindSafe }; -use thiserror::Error; #[cfg(not(feature = "openapi"))] pub trait ResourceType @@ -68,8 +67,8 @@ struct RawImage { pub trait FromBody : Sized { /// 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 - /// [`FromBodyNoError`](struct.FromBodyNoError.html) is used here. + /// macro, there is no way to trigger an error, so `Infallible` is used here. However, this + /// might change in the future. type Err : Error; /// Perform the conversion. @@ -86,12 +85,6 @@ impl 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 diff --git a/gotham_restful_derive/src/from_body.rs b/gotham_restful_derive/src/from_body.rs index 6d48201..f7c04ad 100644 --- a/gotham_restful_derive/src/from_body.rs +++ b/gotham_restful_derive/src/from_body.rs @@ -120,9 +120,9 @@ pub fn expand_from_body(input : DeriveInput) -> Result impl #generics #krate::FromBody for #ident #generics 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 + fn from_body(#body_ident : #krate::gotham::hyper::body::Bytes, #type_ident : #krate::Mime) -> Result { #block Ok(#ctor)