1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

Expose factory traits and some clippy fixes (#983)

This commit is contained in:
Ravi Shankar 2019-07-17 12:28:42 +05:30 committed by Nikolay Kim
parent c01611d8b5
commit 32718b7e31
13 changed files with 16 additions and 9 deletions

View File

@ -118,7 +118,7 @@ impl<T: 'static> FromRequest for Data<T> {
impl<T: 'static> DataFactory for Data<T> { impl<T: 'static> DataFactory for Data<T> {
fn create(&self, extensions: &mut Extensions) -> bool { fn create(&self, extensions: &mut Extensions) -> bool {
if !extensions.contains::<Data<T>>() { if !extensions.contains::<Data<T>>() {
let _ = extensions.insert(Data(self.0.clone())); extensions.insert(Data(self.0.clone()));
true true
} else { } else {
false false

View File

@ -250,7 +250,7 @@ where
Ok(Async::Ready(res)) => { Ok(Async::Ready(res)) => {
self.fut2 = self.fut2 =
Some(res.respond_to(self.req.as_ref().unwrap()).into_future()); Some(res.respond_to(self.req.as_ref().unwrap()).into_future());
return self.poll(); self.poll()
} }
Ok(Async::NotReady) => Ok(Async::NotReady), Ok(Async::NotReady) => Ok(Async::NotReady),
Err(e) => { Err(e) => {

View File

@ -25,7 +25,7 @@ impl ConnectionInfo {
Ref::map(req.extensions(), |e| e.get().unwrap()) Ref::map(req.extensions(), |e| e.get().unwrap())
} }
#[allow(clippy::cyclomatic_complexity)] #[allow(clippy::cyclomatic_complexity, clippy::cognitive_complexity, clippy::borrow_interior_mutable_const)]
fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo { fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo {
let mut host = None; let mut host = None;
let mut scheme = None; let mut scheme = None;

View File

@ -134,6 +134,8 @@ pub mod dev {
//! ``` //! ```
pub use crate::config::{AppConfig, AppService}; pub use crate::config::{AppConfig, AppService};
#[doc(hidden)]
pub use crate::handler::{AsyncFactory, Factory};
pub use crate::info::ConnectionInfo; pub use crate::info::ConnectionInfo;
pub use crate::rmap::ResourceMap; pub use crate::rmap::ResourceMap;
pub use crate::service::{ pub use crate::service::{

View File

@ -107,6 +107,7 @@ where
self.service.poll_ready() self.service.poll_ready()
} }
#[allow(clippy::borrow_interior_mutable_const)]
fn call(&mut self, req: ServiceRequest) -> Self::Future { fn call(&mut self, req: ServiceRequest) -> Self::Future {
// negotiate content-encoding // negotiate content-encoding
let encoding = if let Some(val) = req.headers().get(&ACCEPT_ENCODING) { let encoding = if let Some(val) = req.headers().get(&ACCEPT_ENCODING) {

View File

@ -125,6 +125,7 @@ where
self.service.poll_ready() self.service.poll_ready()
} }
#[allow(clippy::borrow_interior_mutable_const)]
fn call(&mut self, req: ServiceRequest) -> Self::Future { fn call(&mut self, req: ServiceRequest) -> Self::Future {
let inner = self.inner.clone(); let inner = self.inner.clone();

View File

@ -415,9 +415,9 @@ impl FormatText {
)) ))
}; };
} }
FormatText::UrlPath => *self = FormatText::Str(format!("{}", req.path())), FormatText::UrlPath => *self = FormatText::Str(req.path().to_string()),
FormatText::RequestTime => { FormatText::RequestTime => {
*self = FormatText::Str(format!("{}", now.rfc3339())) *self = FormatText::Str(now.rfc3339().to_string())
} }
FormatText::RequestHeader(ref name) => { FormatText::RequestHeader(ref name) => {
let s = if let Some(val) = req.headers().get(name) { let s = if let Some(val) = req.headers().get(name) {

View File

@ -426,7 +426,7 @@ where
fn into_new_service(self) -> T { fn into_new_service(self) -> T {
*self.factory_ref.borrow_mut() = Some(ResourceFactory { *self.factory_ref.borrow_mut() = Some(ResourceFactory {
routes: self.routes, routes: self.routes,
data: self.data.map(|data| Rc::new(data)), data: self.data.map(Rc::new),
default: self.default, default: self.default,
}); });

View File

@ -123,7 +123,7 @@ impl ResourceMap {
I: AsRef<str>, I: AsRef<str>,
{ {
if let Some(pattern) = self.named.get(name) { if let Some(pattern) = self.named.get(name) {
if pattern.pattern().starts_with("/") { if pattern.pattern().starts_with('/') {
self.fill_root(path, elements)?; self.fill_root(path, elements)?;
} }
if pattern.resource_path(path, elements) { if pattern.resource_path(path, elements) {

View File

@ -195,7 +195,7 @@ where
self.external.extend(cfg.external); self.external.extend(cfg.external);
if !cfg.data.is_empty() { if !cfg.data.is_empty() {
let mut data = self.data.unwrap_or_else(|| Extensions::new()); let mut data = self.data.unwrap_or_else(Extensions::new);
for value in cfg.data.iter() { for value in cfg.data.iter() {
value.create(&mut data); value.create(&mut data);
@ -425,7 +425,7 @@ where
// complete scope pipeline creation // complete scope pipeline creation
*self.factory_ref.borrow_mut() = Some(ScopeFactory { *self.factory_ref.borrow_mut() = Some(ScopeFactory {
data: self.data.take().map(|data| Rc::new(data)), data: self.data.take().map(Rc::new),
default: self.default.clone(), default: self.default.clone(),
services: Rc::new( services: Rc::new(
cfg.into_services() cfg.into_services()

View File

@ -192,6 +192,7 @@ pub struct UrlEncoded<U> {
impl<U> UrlEncoded<U> { impl<U> UrlEncoded<U> {
/// Create a new future to URL encode a request /// Create a new future to URL encode a request
#[allow(clippy::borrow_interior_mutable_const)]
pub fn new(req: &HttpRequest, payload: &mut Payload) -> UrlEncoded<U> { pub fn new(req: &HttpRequest, payload: &mut Payload) -> UrlEncoded<U> {
// check content type // check content type
if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" { if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" {

View File

@ -298,6 +298,7 @@ where
U: DeserializeOwned + 'static, U: DeserializeOwned + 'static,
{ {
/// Create `JsonBody` for request. /// Create `JsonBody` for request.
#[allow(clippy::borrow_interior_mutable_const)]
pub fn new( pub fn new(
req: &HttpRequest, req: &HttpRequest,
payload: &mut Payload, payload: &mut Payload,

View File

@ -298,6 +298,7 @@ pub struct HttpMessageBody {
impl HttpMessageBody { impl HttpMessageBody {
/// Create `MessageBody` for request. /// Create `MessageBody` for request.
#[allow(clippy::borrow_interior_mutable_const)]
pub fn new(req: &HttpRequest, payload: &mut dev::Payload) -> HttpMessageBody { pub fn new(req: &HttpRequest, payload: &mut dev::Payload) -> HttpMessageBody {
let mut len = None; let mut len = None;
if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) { if let Some(l) = req.headers().get(&header::CONTENT_LENGTH) {