Skip to content

Commit

Permalink
Merge pull request #1152 from sozu-proxy/apply-clippy-corrections
Browse files Browse the repository at this point in the history
apply clippy suggestions
  • Loading branch information
FlorentinDUBOIS authored Nov 12, 2024
2 parents fcec0b5 + 8162e99 commit 220793a
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 70 deletions.
13 changes: 5 additions & 8 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,7 @@ impl HttpFrontendConfig {
pub fn generate_requests(&self, cluster_id: &str) -> Vec<Request> {
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(
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion command/src/proto/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ fn create_cluster_table(headers: Vec<&str>, data: &BTreeMap<String, ResponseCont

impl Display for SocketAddress {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", SocketAddr::from(self.clone()))
write!(f, "{}", SocketAddr::from(*self))
}
}

Expand Down
2 changes: 1 addition & 1 deletion command/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ pub struct HttpFrontend {

impl From<HttpFrontend> 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(),
hostname: val.hostname,
path: val.path,
method: val.method,
position: val.position.into(),
tags,
tags: val.tags.unwrap_or_default(),
}
}
}
Expand Down
61 changes: 29 additions & 32 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand All @@ -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(_) => {
Expand All @@ -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,
Expand All @@ -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()),
}
}

Expand Down Expand Up @@ -249,23 +249,23 @@ 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,
id: activate.address.to_string(),
}),
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,
id: activate.address.to_string(),
}),
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,
Expand All @@ -278,23 +278,23 @@ 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,
id: deactivate.address.to_string(),
}),
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,
id: deactivate.address.to_string(),
}),
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,
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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()))?,
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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();
Expand All @@ -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 {
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ impl HttpListener {
pub fn new(config: HttpListenerConfig, token: Token) -> Result<HttpListener, ListenerError> {
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))?,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 220793a

Please sign in to comment.