diff --git a/command/src/config.rs b/command/src/config.rs index 85f649c5a..e148cc1d0 100644 --- a/command/src/config.rs +++ b/command/src/config.rs @@ -908,10 +908,7 @@ impl HttpFrontendConfig { pub fn generate_requests(&self, cluster_id: &str) -> Vec { let mut v = Vec::new(); - let tags = match self.tags.clone() { - Some(tags) => tags, - None => BTreeMap::new(), - }; + let tags = self.tags.clone().unwrap_or_default(); if self.key.is_some() && self.certificate.is_some() { v.push( @@ -1586,7 +1583,7 @@ impl Config { for listener in &self.tcp_listeners { v.push(WorkerRequest { id: format!("CONFIG-{count}"), - content: RequestType::AddTcpListener(listener.clone()).into(), + content: RequestType::AddTcpListener(*listener).into(), }); count += 1; } @@ -1607,7 +1604,7 @@ impl Config { v.push(WorkerRequest { id: format!("CONFIG-{count}"), content: RequestType::ActivateListener(ActivateListener { - address: listener.address.clone(), + address: listener.address, proxy: ListenerType::Http.into(), from_scm: false, }) @@ -1620,7 +1617,7 @@ impl Config { v.push(WorkerRequest { id: format!("CONFIG-{count}"), content: RequestType::ActivateListener(ActivateListener { - address: listener.address.clone(), + address: listener.address, proxy: ListenerType::Https.into(), from_scm: false, }) @@ -1633,7 +1630,7 @@ impl Config { v.push(WorkerRequest { id: format!("CONFIG-{count}"), content: RequestType::ActivateListener(ActivateListener { - address: listener.address.clone(), + address: listener.address, proxy: ListenerType::Tcp.into(), from_scm: false, }) diff --git a/command/src/proto/display.rs b/command/src/proto/display.rs index f7173d941..9331de3a7 100644 --- a/command/src/proto/display.rs +++ b/command/src/proto/display.rs @@ -976,7 +976,7 @@ fn create_cluster_table(headers: Vec<&str>, data: &BTreeMap) -> fmt::Result { - write!(f, "{}", SocketAddr::from(self.clone())) + write!(f, "{}", SocketAddr::from(*self)) } } diff --git a/command/src/proto/mod.rs b/command/src/proto/mod.rs index 2f9c7befd..658c15c64 100644 --- a/command/src/proto/mod.rs +++ b/command/src/proto/mod.rs @@ -85,7 +85,7 @@ impl AggregatedMetrics { let found_backend = cluster .backends .iter_mut() - .find(|present| &present.backend_id == &backend.backend_id); + .find(|present| present.backend_id == backend.backend_id); if let Some(existing_backend) = found_backend { let _ = existing_backend diff --git a/command/src/response.rs b/command/src/response.rs index fbda54901..c399b657a 100644 --- a/command/src/response.rs +++ b/command/src/response.rs @@ -43,10 +43,6 @@ pub struct HttpFrontend { impl From for RequestHttpFrontend { fn from(val: HttpFrontend) -> Self { - let tags = match val.tags { - Some(tags) => tags, - None => BTreeMap::new(), - }; RequestHttpFrontend { cluster_id: val.cluster_id, address: val.address.into(), @@ -54,7 +50,7 @@ impl From for RequestHttpFrontend { path: val.path, method: val.method, position: val.position.into(), - tags, + tags: val.tags.unwrap_or_default(), } } } diff --git a/command/src/state.rs b/command/src/state.rs index 5e339f4b8..e8371a8bd 100644 --- a/command/src/state.rs +++ b/command/src/state.rs @@ -175,7 +175,7 @@ impl ConfigState { } fn add_http_listener(&mut self, listener: &HttpListenerConfig) -> Result<(), StateError> { - let address: SocketAddr = listener.address.clone().into(); + let address: SocketAddr = listener.address.into(); match self.http_listeners.entry(address) { BTreeMapEntry::Vacant(vacant_entry) => vacant_entry.insert(listener.clone()), BTreeMapEntry::Occupied(_) => { @@ -189,7 +189,7 @@ impl ConfigState { } fn add_https_listener(&mut self, listener: &HttpsListenerConfig) -> Result<(), StateError> { - let address: SocketAddr = listener.address.clone().into(); + let address: SocketAddr = listener.address.into(); match self.https_listeners.entry(address) { BTreeMapEntry::Vacant(vacant_entry) => vacant_entry.insert(listener.clone()), BTreeMapEntry::Occupied(_) => { @@ -203,9 +203,9 @@ impl ConfigState { } fn add_tcp_listener(&mut self, listener: &TcpListenerConfig) -> Result<(), StateError> { - let address: SocketAddr = listener.address.clone().into(); + let address: SocketAddr = listener.address.into(); match self.tcp_listeners.entry(address) { - BTreeMapEntry::Vacant(vacant_entry) => vacant_entry.insert(listener.clone()), + BTreeMapEntry::Vacant(vacant_entry) => vacant_entry.insert(*listener), BTreeMapEntry::Occupied(_) => { return Err(StateError::Exists { kind: ObjectKind::TcpListener, @@ -218,9 +218,9 @@ impl ConfigState { fn remove_listener(&mut self, remove: &RemoveListener) -> Result<(), StateError> { match ListenerType::try_from(remove.proxy).map_err(StateError::WrongFieldValue)? { - ListenerType::Http => self.remove_http_listener(&remove.address.clone().into()), - ListenerType::Https => self.remove_https_listener(&remove.address.clone().into()), - ListenerType::Tcp => self.remove_tcp_listener(&remove.address.clone().into()), + ListenerType::Http => self.remove_http_listener(&remove.address.into()), + ListenerType::Https => self.remove_https_listener(&remove.address.into()), + ListenerType::Tcp => self.remove_tcp_listener(&remove.address.into()), } } @@ -249,7 +249,7 @@ impl ConfigState { match ListenerType::try_from(activate.proxy).map_err(StateError::WrongFieldValue)? { ListenerType::Http => self .http_listeners - .get_mut(&activate.address.clone().into()) + .get_mut(&activate.address.into()) .map(|listener| listener.active = true) .ok_or(StateError::NotFound { kind: ObjectKind::HttpListener, @@ -257,7 +257,7 @@ impl ConfigState { }), ListenerType::Https => self .https_listeners - .get_mut(&activate.address.clone().into()) + .get_mut(&activate.address.into()) .map(|listener| listener.active = true) .ok_or(StateError::NotFound { kind: ObjectKind::HttpsListener, @@ -265,7 +265,7 @@ impl ConfigState { }), ListenerType::Tcp => self .tcp_listeners - .get_mut(&activate.address.clone().into()) + .get_mut(&activate.address.into()) .map(|listener| listener.active = true) .ok_or(StateError::NotFound { kind: ObjectKind::TcpListener, @@ -278,7 +278,7 @@ impl ConfigState { match ListenerType::try_from(deactivate.proxy).map_err(StateError::WrongFieldValue)? { ListenerType::Http => self .http_listeners - .get_mut(&deactivate.address.clone().into()) + .get_mut(&deactivate.address.into()) .map(|listener| listener.active = false) .ok_or(StateError::NotFound { kind: ObjectKind::HttpListener, @@ -286,7 +286,7 @@ impl ConfigState { }), ListenerType::Https => self .https_listeners - .get_mut(&deactivate.address.clone().into()) + .get_mut(&deactivate.address.into()) .map(|listener| listener.active = false) .ok_or(StateError::NotFound { kind: ObjectKind::HttpsListener, @@ -294,7 +294,7 @@ impl ConfigState { }), ListenerType::Tcp => self .tcp_listeners - .get_mut(&deactivate.address.clone().into()) + .get_mut(&deactivate.address.into()) .map(|listener| listener.active = false) .ok_or(StateError::NotFound { kind: ObjectKind::TcpListener, @@ -373,10 +373,7 @@ impl ConfigState { .fingerprint() .map_err(StateError::AddCertificate)?; - let entry = self - .certificates - .entry(add.address.clone().into()) - .or_default(); + let entry = self.certificates.entry(add.address.into()).or_default(); let mut add = add.clone(); add.certificate @@ -401,7 +398,7 @@ impl ConfigState { .map_err(|decode_error| StateError::RemoveCertificate(decode_error.to_string()))?, ); - if let Some(index) = self.certificates.get_mut(&remove.address.clone().into()) { + if let Some(index) = self.certificates.get_mut(&remove.address.into()) { index.remove(&fingerprint); } @@ -413,7 +410,7 @@ impl ConfigState { /// - insert the new certificate with the new fingerprint as key /// - check that the new entry is present in the certificates hashmap fn replace_certificate(&mut self, replace: &ReplaceCertificate) -> Result<(), StateError> { - let replace_address = replace.address.clone().into(); + let replace_address = replace.address.into(); let old_fingerprint = Fingerprint( hex::decode(&replace.old_fingerprint) .map_err(|decode_error| StateError::RemoveCertificate(decode_error.to_string()))?, @@ -459,7 +456,7 @@ impl ConfigState { let tcp_frontend = TcpFrontend { cluster_id: front.cluster_id.clone(), - address: front.address.clone().into(), + address: front.address.into(), tags: front.tags.clone(), }; if tcp_frontends.contains(&tcp_frontend) { @@ -486,7 +483,7 @@ impl ConfigState { })?; let len = tcp_frontends.len(); - tcp_frontends.retain(|front| front.address != front_to_remove.address.clone().into()); + tcp_frontends.retain(|front| front.address != front_to_remove.address.into()); if tcp_frontends.len() == len { return Err(StateError::NoChange); } @@ -495,11 +492,11 @@ impl ConfigState { fn add_backend(&mut self, add_backend: &AddBackend) -> Result<(), StateError> { let backend = Backend { - address: add_backend.address.clone().into(), + address: add_backend.address.into(), cluster_id: add_backend.cluster_id.clone(), backend_id: add_backend.backend_id.clone(), sticky_id: add_backend.sticky_id.clone(), - load_balancing_parameters: add_backend.load_balancing_parameters.clone(), + load_balancing_parameters: add_backend.load_balancing_parameters, backup: add_backend.backup, }; let backends = self.backends.entry(backend.cluster_id.clone()).or_default(); @@ -522,7 +519,7 @@ impl ConfigState { })?; let len = backend_list.len(); - let remove_address = backend.address.clone().into(); + let remove_address = backend.address.into(); backend_list.retain(|b| b.backend_id != backend.backend_id || b.address != remove_address); backend_list.sort(); if backend_list.len() == len { @@ -540,7 +537,7 @@ impl ConfigState { if listener.active { v.push( RequestType::ActivateListener(ActivateListener { - address: listener.address.clone(), + address: listener.address, proxy: ListenerType::Http.into(), from_scm: false, }) @@ -554,7 +551,7 @@ impl ConfigState { if listener.active { v.push( RequestType::ActivateListener(ActivateListener { - address: listener.address.clone(), + address: listener.address, proxy: ListenerType::Https.into(), from_scm: false, }) @@ -564,11 +561,11 @@ impl ConfigState { } for listener in self.tcp_listeners.values() { - v.push(RequestType::AddTcpListener(listener.clone()).into()); + v.push(RequestType::AddTcpListener(*listener).into()); if listener.active { v.push( RequestType::ActivateListener(ActivateListener { - address: listener.address.clone(), + address: listener.address, proxy: ListenerType::Tcp.into(), from_scm: false, }) @@ -710,7 +707,7 @@ impl ConfigState { } for address in added_tcp_listeners.clone() { - v.push(RequestType::AddTcpListener(other.tcp_listeners[*address].clone()).into()); + v.push(RequestType::AddTcpListener(other.tcp_listeners[*address]).into()); if other.tcp_listeners[*address].active { v.push( @@ -809,7 +806,7 @@ impl ConfigState { .into(), ); // any added listener should be unactive - let mut listener_to_add = their_listener.clone(); + let mut listener_to_add = *their_listener; listener_to_add.active = false; v.push(RequestType::AddTcpListener(listener_to_add).into()); } @@ -1102,7 +1099,7 @@ impl ConfigState { if listener.active { v.push( RequestType::ActivateListener(ActivateListener { - address: listener.address.clone(), + address: listener.address, proxy: ListenerType::Tcp.into(), from_scm: false, }) @@ -1316,7 +1313,7 @@ impl ConfigState { tcp_listeners: self .tcp_listeners .iter() - .map(|(addr, listener)| (addr.to_string(), listener.clone())) + .map(|(addr, listener)| (addr.to_string(), *listener)) .collect(), } } diff --git a/lib/src/backends.rs b/lib/src/backends.rs index 2b3d1e087..0de77c434 100644 --- a/lib/src/backends.rs +++ b/lib/src/backends.rs @@ -383,7 +383,7 @@ impl BackendList { &backend.backend_id, backend.address, backend.sticky_id.clone(), - backend.load_balancing_parameters.clone(), + backend.load_balancing_parameters, backend.backup, ); list.add_backend(backend); diff --git a/lib/src/http.rs b/lib/src/http.rs index b1be32ec9..75032c1d7 100644 --- a/lib/src/http.rs +++ b/lib/src/http.rs @@ -723,7 +723,7 @@ impl HttpListener { pub fn new(config: HttpListenerConfig, token: Token) -> Result { Ok(HttpListener { active: false, - address: config.address.clone().into(), + address: config.address.into(), answers: Rc::new(RefCell::new( HttpAnswers::new(&config.http_answers) .map_err(|(status, error)| ListenerError::TemplateParse(status, error))?, @@ -744,7 +744,7 @@ impl HttpListener { if self.active { return Ok(self.token); } - let address: SocketAddr = self.config.address.clone().into(); + let address: SocketAddr = self.config.address.into(); let mut listener = match tcp_listener { Some(tcp_listener) => tcp_listener, @@ -910,9 +910,9 @@ impl ProxyConfiguration for HttpProxy { return Err(AcceptError::RegisterError); } - let public_address: SocketAddr = match owned.config.public_address.clone() { + let public_address: SocketAddr = match owned.config.public_address { Some(pub_addr) => pub_addr.into(), - None => owned.config.address.clone().into(), + None => owned.config.address.into(), }; let session = HttpSession::new( @@ -992,7 +992,7 @@ pub mod testing { max_buffers: usize, buffer_size: usize, ) -> anyhow::Result<()> { - let address = config.address.clone().into(); + let address = config.address.into(); let ServerParts { event_loop, diff --git a/lib/src/https.rs b/lib/src/https.rs index 3a9ccc902..709809d38 100644 --- a/lib/src/https.rs +++ b/lib/src/https.rs @@ -618,7 +618,7 @@ impl HttpsListener { Ok(HttpsListener { listener: None, - address: config.address.clone().into(), + address: config.address.into(), resolver, rustls_details: server_config, active: false, @@ -641,7 +641,7 @@ impl HttpsListener { if self.active { return Ok(self.token); } - let address: StdSocketAddr = self.config.address.clone().into(); + let address: StdSocketAddr = self.config.address.into(); let mut listener = match tcp_listener { Some(tcp_listener) => tcp_listener, @@ -1082,7 +1082,7 @@ impl HttpsProxy { &mut self, add_certificate: AddCertificate, ) -> Result, ProxyError> { - let address = add_certificate.address.clone().into(); + let address = add_certificate.address.into(); let listener = self .listeners @@ -1141,7 +1141,7 @@ impl HttpsProxy { &mut self, replace_certificate: ReplaceCertificate, ) -> Result, ProxyError> { - let address = replace_certificate.address.clone().into(); + let address = replace_certificate.address.into(); let listener = self .listeners @@ -1214,9 +1214,9 @@ impl ProxyConfiguration for HttpsProxy { AcceptError::RegisterError })?; - let public_address: StdSocketAddr = match owned.config.public_address.clone() { + let public_address: StdSocketAddr = match owned.config.public_address { Some(pub_addr) => pub_addr.into(), - None => owned.config.address.clone().into(), + None => owned.config.address.into(), }; let session = Rc::new(RefCell::new(HttpsSession::new( @@ -1443,7 +1443,7 @@ pub mod testing { max_buffers: usize, buffer_size: usize, ) -> anyhow::Result<()> { - let address = config.address.clone().into(); + let address = config.address.into(); let ServerParts { event_loop, diff --git a/lib/src/protocol/kawa_h1/mod.rs b/lib/src/protocol/kawa_h1/mod.rs index 3f3709690..1e2c86532 100644 --- a/lib/src/protocol/kawa_h1/mod.rs +++ b/lib/src/protocol/kawa_h1/mod.rs @@ -177,10 +177,12 @@ pub struct Http { impl Http { /// Instantiate a new HTTP SessionState with: + /// /// - frontend_interest: READABLE | HUP | ERROR /// - frontend_event: EMPTY /// - backend_interest: EMPTY /// - backend_event: EMPTY + /// /// Remember to set the events from the previous State! #[allow(clippy::too_many_arguments)] pub fn new( diff --git a/lib/src/protocol/pipe.rs b/lib/src/protocol/pipe.rs index 88fe157e6..63d9dffc0 100644 --- a/lib/src/protocol/pipe.rs +++ b/lib/src/protocol/pipe.rs @@ -84,10 +84,12 @@ pub struct Pipe { impl Pipe { /// Instantiate a new Pipe SessionState with: + /// /// - frontend_interest: READABLE | WRITABLE | HUP | ERROR /// - frontend_event: EMPTY /// - backend_interest: READABLE | WRITABLE | HUP | ERROR /// - backend_event: EMPTY + /// /// Remember to set the events from the previous State! #[allow(clippy::too_many_arguments)] pub fn new( diff --git a/lib/src/protocol/rustls.rs b/lib/src/protocol/rustls.rs index a6116188a..e84aa8cb5 100644 --- a/lib/src/protocol/rustls.rs +++ b/lib/src/protocol/rustls.rs @@ -51,8 +51,10 @@ pub struct TlsHandshake { impl TlsHandshake { /// Instantiate a new TlsHandshake SessionState with: + /// /// - frontend_interest: READABLE | HUP | ERROR /// - frontend_event: EMPTY + /// /// Remember to set the events from the previous State! pub fn new( container_frontend_timeout: TimeoutContainer, diff --git a/lib/src/server.rs b/lib/src/server.rs index 5c4be7e4b..21234aa44 100644 --- a/lib/src/server.rs +++ b/lib/src/server.rs @@ -1064,9 +1064,9 @@ impl Server { fn add_backend(&mut self, req_id: &str, add_backend: &AddBackend) -> WorkerResponse { let new_backend = Backend::new( &add_backend.backend_id, - add_backend.address.clone().into(), + add_backend.address.into(), add_backend.sticky_id.clone(), - add_backend.load_balancing_parameters.clone(), + add_backend.load_balancing_parameters, add_backend.backup, ); self.backends @@ -1077,7 +1077,7 @@ impl Server { } fn remove_backend(&mut self, req_id: &str, backend: &RemoveBackend) -> WorkerResponse { - let address = backend.address.clone().into(); + let address = backend.address.into(); self.backends .borrow_mut() .remove_backend(&backend.cluster_id, &address); @@ -1180,7 +1180,7 @@ impl Server { req_id, activate.proxy, activate ); - let address: std::net::SocketAddr = activate.address.clone().into(); + let address: std::net::SocketAddr = activate.address.into(); match ListenerType::try_from(activate.proxy) { Ok(ListenerType::Http) => { @@ -1257,7 +1257,7 @@ impl Server { req_id, deactivate.proxy, deactivate ); - let address: std::net::SocketAddr = deactivate.address.clone().into(); + let address: std::net::SocketAddr = deactivate.address.into(); match ListenerType::try_from(deactivate.proxy) { Ok(ListenerType::Http) => { diff --git a/lib/src/tcp.rs b/lib/src/tcp.rs index 9005ed9fe..087e84f89 100644 --- a/lib/src/tcp.rs +++ b/lib/src/tcp.rs @@ -1120,7 +1120,7 @@ impl TcpListener { cluster_id: None, listener: None, token, - address: config.address.clone().into(), + address: config.address.into(), config, active: false, tags: BTreeMap::new(), @@ -1139,7 +1139,7 @@ impl TcpListener { let mut listener = match tcp_listener { Some(listener) => listener, None => { - let address = self.config.address.clone().into(); + let address = self.config.address.into(); server_bind(address).map_err(|e| ProxyError::BindToSocket(address, e))? } }; @@ -1377,7 +1377,7 @@ impl ProxyConfiguration for TcpProxy { WorkerResponse::ok(message.id) } RequestType::RemoveListener(remove) => { - if !self.remove_listener(remove.address.clone().into()) { + if !self.remove_listener(remove.address.into()) { WorkerResponse::error( message.id, format!("no TCP listener to remove at address {:?}", remove.address), @@ -1518,7 +1518,7 @@ pub mod testing { buffer_size: usize, channel: ProxyChannel, ) -> anyhow::Result<()> { - let address = config.address.clone().into(); + let address = config.address.into(); let ServerParts { event_loop, diff --git a/lib/src/timer.rs b/lib/src/timer.rs index f576e199b..4c99bdbfd 100644 --- a/lib/src/timer.rs +++ b/lib/src/timer.rs @@ -7,7 +7,6 @@ use std::{ fmt::Display, iter, time::{Duration, Instant}, - u64, usize, }; use mio::Token;