From d765e9099dbda47831a72d3fa149ec03f4e37576 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 10 Oct 2020 02:26:05 +0200 Subject: [PATCH] Fix clippy::rc_buffer (#1728) --- src/app.rs | 4 ++-- src/app_service.rs | 26 +++++++++++++------------- src/config.rs | 4 ++-- src/lib.rs | 1 - src/route.rs | 2 ++ src/scope.rs | 23 ++++++++++++----------- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/app.rs b/src/app.rs index fdedb0a75..6a4b97b69 100644 --- a/src/app.rs +++ b/src/app.rs @@ -459,8 +459,8 @@ where { fn into_factory(self) -> AppInit { AppInit { - data: Rc::new(self.data), - data_factories: Rc::new(self.data_factories), + data: self.data.into_boxed_slice().into(), + data_factories: self.data_factories.into_boxed_slice().into(), endpoint: self.endpoint, services: Rc::new(RefCell::new(self.services)), external: RefCell::new(self.external), diff --git a/src/app_service.rs b/src/app_service.rs index 98d8c8a8d..e5f8dd9cf 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -39,8 +39,8 @@ where { pub(crate) endpoint: T, pub(crate) extensions: RefCell>, - pub(crate) data: Rc>>, - pub(crate) data_factories: Rc>, + pub(crate) data: Rc<[Box]>, + pub(crate) data_factories: Rc<[FnDataFactory]>, pub(crate) services: Rc>>>, pub(crate) default: Option>, pub(crate) factory_ref: Rc>>, @@ -88,15 +88,15 @@ where // complete pipeline creation *self.factory_ref.borrow_mut() = Some(AppRoutingFactory { default, - services: Rc::new( - services - .into_iter() - .map(|(mut rdef, srv, guards, nested)| { - rmap.add(&mut rdef, nested); - (rdef, srv, RefCell::new(guards)) - }) - .collect(), - ), + services: services + .into_iter() + .map(|(mut rdef, srv, guards, nested)| { + rmap.add(&mut rdef, nested); + (rdef, srv, RefCell::new(guards)) + }) + .collect::>() + .into_boxed_slice() + .into(), }); // external resources @@ -147,7 +147,7 @@ where rmap: Rc, config: AppConfig, - data: Rc>>, + data: Rc<[Box]>, extensions: Option, _t: PhantomData, @@ -273,7 +273,7 @@ where } pub struct AppRoutingFactory { - services: Rc>)>>, + services: Rc<[(ResourceDef, HttpNewService, RefCell>)]>, default: Rc, } diff --git a/src/config.rs b/src/config.rs index 0f49288ec..f7bebb4c5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -31,7 +31,7 @@ pub struct AppService { Option, Option>, )>, - service_data: Rc>>, + service_data: Rc<[Box]>, } impl AppService { @@ -39,7 +39,7 @@ impl AppService { pub(crate) fn new( config: AppConfig, default: Rc, - service_data: Rc>>, + service_data: Rc<[Box]>, ) -> Self { AppService { config, diff --git a/src/lib.rs b/src/lib.rs index edc8456ba..327cba954 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,6 @@ #![deny(rust_2018_idioms)] #![allow(clippy::needless_doctest_main, clippy::type_complexity)] -#![allow(clippy::rc_buffer)] // FXIME: We should take a closer look for the warnings at some point. #![doc(html_logo_url = "https://actix.rs/img/logo.png")] #![doc(html_favicon_url = "https://actix.rs/favicon.ico")] diff --git a/src/route.rs b/src/route.rs index 129a67332..e9e9d1f5d 100644 --- a/src/route.rs +++ b/src/route.rs @@ -1,3 +1,5 @@ +#![allow(clippy::rc_buffer)] // inner value is mutated before being shared (`Rc::get_mut`) + use std::future::Future; use std::pin::Pin; use std::rc::Rc; diff --git a/src/scope.rs b/src/scope.rs index 2520fd7ae..1c5d8700b 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -442,16 +442,17 @@ where *self.factory_ref.borrow_mut() = Some(ScopeFactory { data: self.data.take().map(Rc::new), default: self.default.clone(), - services: Rc::new( - cfg.into_services() - .1 - .into_iter() - .map(|(mut rdef, srv, guards, nested)| { - rmap.add(&mut rdef, nested); - (rdef, srv, RefCell::new(guards)) - }) - .collect(), - ), + services: cfg + .into_services() + .1 + .into_iter() + .map(|(mut rdef, srv, guards, nested)| { + rmap.add(&mut rdef, nested); + (rdef, srv, RefCell::new(guards)) + }) + .collect::>() + .into_boxed_slice() + .into(), }); // get guards @@ -473,7 +474,7 @@ where pub struct ScopeFactory { data: Option>, - services: Rc>)>>, + services: Rc<[(ResourceDef, HttpNewService, RefCell>)]>, default: Rc>>>, }