diff --git a/src/error.rs b/src/error.rs index c53a433..282dc80 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,7 +5,6 @@ use actix_http::error::PayloadError; use actix_http::http::StatusCode; use actix_http::ResponseError; use actix_web::HttpResponse; -use futures_util::core_reexport::fmt::{Display, Formatter}; #[derive(Debug)] pub struct CborError(serde_cbor::Error); @@ -40,8 +39,8 @@ impl From for CborPayloadError { } } -impl Display for CborPayloadError { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { +impl fmt::Display for CborPayloadError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { CborPayloadError::Overflow => writeln!(f, "Cbor payload size is bigger than allowed"), CborPayloadError::ContentType => writeln!(f, "Content type error"), @@ -61,9 +60,7 @@ impl Error for CborPayloadError {} impl ResponseError for CborPayloadError { fn error_response(&self) -> HttpResponse { match *self { - CborPayloadError::Overflow => { - HttpResponse::new(StatusCode::PAYLOAD_TOO_LARGE) - } + CborPayloadError::Overflow => HttpResponse::new(StatusCode::PAYLOAD_TOO_LARGE), _ => HttpResponse::new(StatusCode::BAD_REQUEST), } } @@ -87,4 +84,4 @@ impl From for CborError { fn from(e: serde_cbor::Error) -> Self { Self(e) } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index b75d321..188748b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,13 +24,12 @@ extern crate serde; use std::fmt; use std::ops::{Deref, DerefMut}; -use actix_http::{Payload, PayloadStream, Response}; use actix_http::http::StatusCode; -use actix_web::{FromRequest, HttpRequest, Responder}; +use actix_http::{Payload, PayloadStream, Response}; #[cfg(feature = "compress")] use actix_web::dev::Decompress; -use futures_util::core_reexport::fmt::Formatter; -use futures_util::future::{err, LocalBoxFuture, ok, Ready}; +use actix_web::{FromRequest, HttpRequest, Responder}; +use futures_util::future::{err, ok, LocalBoxFuture, Ready}; use futures_util::FutureExt; use serde::de::DeserializeOwned; use serde::Serialize; @@ -39,9 +38,9 @@ pub use body::*; pub use config::*; pub use error::*; -mod error; -mod config; mod body; +mod config; +mod error; #[cfg(test)] mod tests; @@ -93,20 +92,26 @@ impl DerefMut for Cbor { } } -impl fmt::Debug for Cbor where T: fmt::Debug { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { +impl fmt::Debug for Cbor +where + T: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Cbor: {:?}", self.0) } } -impl Responder for Cbor where T: Serialize { +impl Responder for Cbor +where + T: Serialize, +{ type Error = CborError; type Future = Ready>; fn respond_to(self, _: &HttpRequest) -> Self::Future { let body = match serde_cbor::to_vec(&self.0) { Ok(body) => body, - Err(e) => return err(e.into()) + Err(e) => return err(e.into()), }; ok(Response::build(StatusCode::OK) @@ -115,7 +120,10 @@ impl Responder for Cbor where T: Serialize { } } -impl FromRequest for Cbor where T: DeserializeOwned + 'static { +impl FromRequest for Cbor +where + T: DeserializeOwned + 'static, +{ type Error = actix_web::Error; type Future = LocalBoxFuture<'static, Result>; type Config = CborConfig; @@ -148,4 +156,4 @@ impl FromRequest for Cbor where T: DeserializeOwned + 'static { }) .boxed_local() } -} \ No newline at end of file +}