Skip to content

Commit

Permalink
ci(clippy): remove useless conversions and more
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Sep 8, 2023
1 parent 06fff4c commit 9107f04
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion plugins/actix-web/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ where
F: Mountable,
{
let mut api = self.spec.write().unwrap();
api.definitions.extend(factory.definitions().into_iter());
api.definitions.extend(factory.definitions());
SecurityScheme::append_map(
factory.security_definitions(),
&mut api.security_definitions,
Expand Down
4 changes: 2 additions & 2 deletions plugins/actix-web/src/app3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
Mountable,
};
use actix_service1::ServiceFactory;
#[cfg(any(feature = "swagger-ui"))]
#[cfg(feature = "swagger-ui")]
use actix_web::web::HttpRequest;
use actix_web::{
dev::{HttpServiceFactory, MessageBody, ServiceRequest, ServiceResponse, Transform},
Expand Down Expand Up @@ -454,7 +454,7 @@ where
F: Mountable,
{
let mut api = self.spec.write().unwrap();
api.definitions.extend(factory.definitions().into_iter());
api.definitions.extend(factory.definitions());
SecurityScheme::append_map(
factory.security_definitions(),
&mut api.security_definitions,
Expand Down
6 changes: 2 additions & 4 deletions plugins/actix-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ pub trait Mountable {
fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
let operations = self.operations();
if !operations.is_empty() {
let op_map = map
.entry(self.path().into())
.or_insert_with(Default::default);
op_map.methods.extend(operations.into_iter());
let op_map = map.entry(self.path().into()).or_default();
op_map.methods.extend(operations);
}
}
}
20 changes: 10 additions & 10 deletions plugins/actix-web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ where
/// Wrapper for [`actix_web::Resource::route`](https://docs.rs/actix-web/*/actix_web/struct.Resource.html#method.route).
pub fn route(mut self, route: Route) -> Self {
let w = RouteWrapper::from(&self.path, route);
self.operations.extend(w.operations.into_iter());
self.definitions.extend(w.definitions.into_iter());
self.operations.extend(w.operations);
self.definitions.extend(w.definitions);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner = self.inner.route(w.inner);
self
Expand Down Expand Up @@ -248,7 +248,7 @@ where
self.operations.insert(method.into(), op.clone());
}

self.definitions.extend(U::definitions().into_iter());
self.definitions.extend(U::definitions());
SecurityScheme::append_map(U::security_definitions(), &mut self.security);
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ where
where
M: Mountable,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
let mut path_map = BTreeMap::new();
factory.update_operations(&mut path_map);
for (path, mut map) in path_map {
Expand Down Expand Up @@ -488,8 +488,8 @@ impl<T> Mountable for Scope<T> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand Down Expand Up @@ -719,8 +719,8 @@ impl<'a> Mountable for ServiceConfig<'a> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand All @@ -729,7 +729,7 @@ impl<'a> ServiceConfig<'a> {
/// Wrapper for [`actix_web::web::ServiceConfig::route`](https://docs.rs/actix-web/*/actix_web/web/struct.ServiceConfig.html#method.route).
pub fn route(&mut self, path: &str, route: Route) -> &mut Self {
let mut w = RouteWrapper::from(path, route);
self.definitions.extend(w.definitions().into_iter());
self.definitions.extend(w.definitions());
w.update_operations(&mut self.path_map);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner.route(path, w.inner);
Expand All @@ -741,7 +741,7 @@ impl<'a> ServiceConfig<'a> {
where
F: Mountable + HttpServiceFactory + 'static,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
factory.update_operations(&mut self.path_map);
SecurityScheme::append_map(factory.security_definitions(), &mut self.security);
self.inner.service(factory);
Expand Down
20 changes: 10 additions & 10 deletions plugins/actix-web/src/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ where
/// Wrapper for [`actix_web::Resource::route`](https://docs.rs/actix-web/*/actix_web/struct.Resource.html#method.route).
pub fn route(mut self, route: Route) -> Self {
let w = RouteWrapper::from(&self.path, route);
self.operations.extend(w.operations.into_iter());
self.definitions.extend(w.definitions.into_iter());
self.operations.extend(w.operations);
self.definitions.extend(w.definitions);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner = self.inner.route(w.inner);
self
Expand Down Expand Up @@ -271,7 +271,7 @@ where
self.operations.insert(method.into(), op.clone());
}

self.definitions.extend(U::definitions().into_iter());
self.definitions.extend(U::definitions());
SecurityScheme::append_map(U::security_definitions(), &mut self.security);
}
}
Expand Down Expand Up @@ -479,7 +479,7 @@ where
where
M: Mountable,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
let mut path_map = BTreeMap::new();
factory.update_operations(&mut path_map);
for (path, mut map) in path_map {
Expand Down Expand Up @@ -523,8 +523,8 @@ impl<T> Mountable for Scope<T> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand Down Expand Up @@ -752,8 +752,8 @@ impl<'a> Mountable for ServiceConfig<'a> {

fn update_operations(&mut self, map: &mut BTreeMap<String, DefaultPathItemRaw>) {
for (path, item) in mem::take(&mut self.path_map) {
let op_map = map.entry(path).or_insert_with(Default::default);
op_map.methods.extend(item.methods.into_iter());
let op_map = map.entry(path).or_default();
op_map.methods.extend(item.methods);
}
}
}
Expand All @@ -762,7 +762,7 @@ impl<'a> ServiceConfig<'a> {
/// Wrapper for [`actix_web::web::ServiceConfig::route`](https://docs.rs/actix-web/*/actix_web/web/struct.ServiceConfig.html#method.route).
pub fn route(&mut self, path: &str, route: Route) -> &mut Self {
let mut w = RouteWrapper::from(path, route);
self.definitions.extend(w.definitions().into_iter());
self.definitions.extend(w.definitions());
w.update_operations(&mut self.path_map);
SecurityScheme::append_map(w.security, &mut self.security);
self.inner.route(path, w.inner);
Expand All @@ -774,7 +774,7 @@ impl<'a> ServiceConfig<'a> {
where
F: Mountable + HttpServiceFactory + 'static,
{
self.definitions.extend(factory.definitions().into_iter());
self.definitions.extend(factory.definitions());
factory.update_operations(&mut self.path_map);
SecurityScheme::append_map(factory.security_definitions(), &mut self.security);
self.inner.service(factory);
Expand Down
6 changes: 3 additions & 3 deletions src/v2/codegen/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ where
let mut mods = state.mod_children.borrow_mut();
for (i, path) in rel_path.ancestors().enumerate() {
if let (Some(parent), Some(name)) = (path.parent(), path.file_name()) {
let entry = mods.entry(parent.into()).or_insert_with(HashSet::new);
let entry = mods.entry(parent.into()).or_default();
entry.insert(ChildModule {
name: name.to_string_lossy().into_owned(),
is_final: i == 0,
Expand Down Expand Up @@ -973,7 +973,7 @@ where
let ops = obj[0] // first object is always the globally defined object.
.paths
.entry(self.path.into())
.or_insert_with(Default::default);
.or_default();

let mut response_contains_any = false;
let response_ty_path = if let Some(s) = Self::get_2xx_response_schema(op) {
Expand Down Expand Up @@ -1093,7 +1093,7 @@ where
let ops = obj[0] // first object is always the globally defined object.
.paths
.entry(self.path.into())
.or_insert_with(Default::default);
.or_default();

ops.req.insert(
meth,
Expand Down

0 comments on commit 9107f04

Please sign in to comment.