From 4719bd68033e01894b337114924cc6da00723959 Mon Sep 17 00:00:00 2001 From: yngrtc Date: Fri, 14 Jun 2024 11:29:48 -0700 Subject: [PATCH] fix clippy --- rtc-dtls/src/config.rs | 2 +- rtc-dtls/src/flight/flight0.rs | 2 +- rtc-dtls/src/flight/flight1.rs | 2 +- rtc-dtls/src/flight/flight3.rs | 6 +++--- rtc-dtls/src/flight/flight4.rs | 6 ++++-- rtc-dtls/src/flight/flight5.rs | 8 ++++++-- rtc-dtls/src/state.rs | 7 ++++--- rtc-ice/src/candidate/mod.rs | 2 +- .../payload_feedbacks/slice_loss_indication/mod.rs | 2 +- .../transport_feedbacks/transport_layer_cc/mod.rs | 12 ++++++------ .../transport_feedbacks/transport_layer_nack/mod.rs | 2 +- rtc/src/api/mod.rs | 6 +----- rtc/src/peer_connection/configuration.rs | 1 + rtc/src/peer_connection/mod.rs | 8 ++++---- rtc/src/peer_connection/sdp/mod.rs | 2 +- rtc/src/transport/ice_transport/ice_server.rs | 4 ++-- 16 files changed, 38 insertions(+), 34 deletions(-) diff --git a/rtc-dtls/src/config.rs b/rtc-dtls/src/config.rs index 921e872..a2f0ee5 100644 --- a/rtc-dtls/src/config.rs +++ b/rtc-dtls/src/config.rs @@ -316,7 +316,7 @@ impl ConfigBuilder { server_name = remote_addr.ip().to_string(); } else { warn!("conn.remote_addr is empty, please set explicitly server_name in Config! Use default \"localhost\" as server_name now"); - server_name = "localhost".to_owned(); + "localhost".clone_into(&mut server_name); } } diff --git a/rtc-dtls/src/flight/flight0.rs b/rtc-dtls/src/flight/flight0.rs index 8a69549..bf29824 100644 --- a/rtc-dtls/src/flight/flight0.rs +++ b/rtc-dtls/src/flight/flight0.rs @@ -128,7 +128,7 @@ impl Flight for Flight0 { } } Extension::ServerName(e) => { - state.server_name = e.server_name.clone(); // remote server name + state.server_name.clone_from(&e.server_name); // remote server name } _ => {} } diff --git a/rtc-dtls/src/flight/flight1.rs b/rtc-dtls/src/flight/flight1.rs index fd2502c..26d66ac 100644 --- a/rtc-dtls/src/flight/flight1.rs +++ b/rtc-dtls/src/flight/flight1.rs @@ -95,7 +95,7 @@ impl Flight for Flight1 { )); } - state.cookie = h.cookie.clone(); + state.cookie.clone_from(&h.cookie); state.handshake_recv_sequence = seq; Ok(Box::new(Flight3 {})) } else { diff --git a/rtc-dtls/src/flight/flight3.rs b/rtc-dtls/src/flight/flight3.rs index 31d6c15..e0021c2 100644 --- a/rtc-dtls/src/flight/flight3.rs +++ b/rtc-dtls/src/flight/flight3.rs @@ -84,7 +84,7 @@ impl Flight for Flight3 { )); } - state.cookie = h.cookie.clone(); + state.cookie.clone_from(&h.cookie); state.handshake_recv_sequence = seq; return Ok(Box::new(Flight3 {}) as Box); } @@ -292,7 +292,7 @@ impl Flight for Flight3 { )) } }; - state.peer_certificates = h.certificate.clone(); + state.peer_certificates.clone_from(&h.certificate); } if let Some(message) = msgs.get(&HandshakeType::ServerKeyExchange) { @@ -420,7 +420,7 @@ pub(crate) fn handle_server_key_exchange( } }; - state.identity_hint = h.identity_hint.clone(); + state.identity_hint.clone_from(&h.identity_hint); state.pre_master_secret = prf_psk_pre_master_secret(&psk); } else { let local_keypair = match h.named_curve.generate_keypair() { diff --git a/rtc-dtls/src/flight/flight4.rs b/rtc-dtls/src/flight/flight4.rs index e99b88d..8117349 100644 --- a/rtc-dtls/src/flight/flight4.rs +++ b/rtc-dtls/src/flight/flight4.rs @@ -103,7 +103,7 @@ impl Flight for Flight4 { } }; - state.peer_certificates = h.certificate.clone(); + state.peer_certificates.clone_from(&h.certificate); debug!( "[handshake] PeerCertificates4 {}", state.peer_certificates.len() @@ -300,7 +300,9 @@ impl Flight for Flight4 { } }; - state.identity_hint = client_key_exchange.identity_hint.clone(); + state + .identity_hint + .clone_from(&client_key_exchange.identity_hint); pre_master_secret = prf_psk_pre_master_secret(&psk); } else if let Some(local_keypair) = &state.local_keypair { pre_master_secret = match prf_pre_master_secret( diff --git a/rtc-dtls/src/flight/flight5.rs b/rtc-dtls/src/flight/flight5.rs index 9026987..2211250 100644 --- a/rtc-dtls/src/flight/flight5.rs +++ b/rtc-dtls/src/flight/flight5.rs @@ -217,10 +217,14 @@ impl Flight for Flight5 { }; if cfg.local_psk_callback.is_none() { if let Some(local_keypair) = &state.local_keypair { - client_key_exchange.public_key = local_keypair.public_key.clone(); + client_key_exchange + .public_key + .clone_from(&local_keypair.public_key); } } else if let Some(local_psk_identity_hint) = &cfg.local_psk_identity_hint { - client_key_exchange.identity_hint = local_psk_identity_hint.clone(); + client_key_exchange + .identity_hint + .clone_from(local_psk_identity_hint); } pkts.push(Packet { diff --git a/rtc-dtls/src/state.rs b/rtc-dtls/src/state.rs index 6de1f56..987e27d 100644 --- a/rtc-dtls/src/state.rs +++ b/rtc-dtls/src/state.rs @@ -160,7 +160,7 @@ impl State { self.is_client = serialized.is_client; // Set master secret - self.master_secret = serialized.master_secret.clone(); + self.master_secret.clone_from(&serialized.master_secret); // Set cipher suite self.cipher_suite = Some(cipher_suite_for_id(serialized.cipher_suite_id.into())?); @@ -168,8 +168,9 @@ impl State { self.srtp_protection_profile = serialized.srtp_protection_profile.into(); // Set remote certificate - self.peer_certificates = serialized.peer_certificates.clone(); - self.identity_hint = serialized.identity_hint.clone(); + self.peer_certificates + .clone_from(&serialized.peer_certificates); + self.identity_hint.clone_from(&serialized.identity_hint); Ok(()) } diff --git a/rtc-ice/src/candidate/mod.rs b/rtc-ice/src/candidate/mod.rs index b7444d5..787f18b 100644 --- a/rtc-ice/src/candidate/mod.rs +++ b/rtc-ice/src/candidate/mod.rs @@ -466,7 +466,7 @@ pub fn unmarshal_candidate(raw: &str) -> Result { } // RelatedAddress - rel_addr = split2[1].to_owned(); + split2[1].clone_into(&mut rel_addr); // RelatedPort rel_port = split2[3].parse()?; diff --git a/rtc-rtcp/src/payload_feedbacks/slice_loss_indication/mod.rs b/rtc-rtcp/src/payload_feedbacks/slice_loss_indication/mod.rs index 88c3024..8437b70 100644 --- a/rtc-rtcp/src/payload_feedbacks/slice_loss_indication/mod.rs +++ b/rtc-rtcp/src/payload_feedbacks/slice_loss_indication/mod.rs @@ -94,7 +94,7 @@ impl MarshalSize for SliceLossIndication { impl Marshal for SliceLossIndication { /// Marshal encodes the SliceLossIndication in binary fn marshal_to(&self, mut buf: &mut [u8]) -> Result { - if (self.sli_entries.len() + SLI_LENGTH) as u8 > std::u8::MAX { + if (self.sli_entries.len() + SLI_LENGTH) as u8 > u8::MAX { return Err(Error::TooManyReports); } if buf.remaining_mut() < self.marshal_size() { diff --git a/rtc-rtcp/src/transport_feedbacks/transport_layer_cc/mod.rs b/rtc-rtcp/src/transport_feedbacks/transport_layer_cc/mod.rs index 05a0124..2aa6ff0 100644 --- a/rtc-rtcp/src/transport_feedbacks/transport_layer_cc/mod.rs +++ b/rtc-rtcp/src/transport_feedbacks/transport_layer_cc/mod.rs @@ -320,15 +320,15 @@ impl MarshalSize for RecvDelta { // small delta if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedSmallDelta && delta >= 0 - && delta <= std::u8::MAX as i64 + && delta <= u8::MAX as i64 { return 1; } // big delta if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedLargeDelta - && delta >= std::i16::MIN as i64 - && delta <= std::u16::MAX as i64 + && delta >= i16::MIN as i64 + && delta <= u16::MAX as i64 { return 2; } @@ -345,7 +345,7 @@ impl Marshal for RecvDelta { // small delta if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedSmallDelta && delta >= 0 - && delta <= std::u8::MAX as i64 + && delta <= u8::MAX as i64 && buf.remaining_mut() >= 1 { buf.put_u8(delta as u8); @@ -354,8 +354,8 @@ impl Marshal for RecvDelta { // big delta if self.type_tcc_packet == SymbolTypeTcc::PacketReceivedLargeDelta - && delta >= std::i16::MIN as i64 - && delta <= std::u16::MAX as i64 + && delta >= i16::MIN as i64 + && delta <= u16::MAX as i64 && buf.remaining_mut() >= 2 { buf.put_u16(delta as u16); diff --git a/rtc-rtcp/src/transport_feedbacks/transport_layer_nack/mod.rs b/rtc-rtcp/src/transport_feedbacks/transport_layer_nack/mod.rs index 10500de..1ddd225 100644 --- a/rtc-rtcp/src/transport_feedbacks/transport_layer_nack/mod.rs +++ b/rtc-rtcp/src/transport_feedbacks/transport_layer_nack/mod.rs @@ -172,7 +172,7 @@ impl MarshalSize for TransportLayerNack { impl Marshal for TransportLayerNack { /// Marshal encodes the packet in binary. fn marshal_to(&self, mut buf: &mut [u8]) -> Result { - if self.nacks.len() + TLN_LENGTH > std::u8::MAX as usize { + if self.nacks.len() + TLN_LENGTH > u8::MAX as usize { return Err(Error::TooManyReports); } if buf.remaining_mut() < self.marshal_size() { diff --git a/rtc/src/api/mod.rs b/rtc/src/api/mod.rs index d8e3079..55ebad9 100644 --- a/rtc/src/api/mod.rs +++ b/rtc/src/api/mod.rs @@ -168,11 +168,7 @@ impl APIBuilder { } else { Arc::new(SettingEngine::default()) }, - media_engine: if let Some(media_engine) = self.media_engine.take() { - media_engine - } else { - MediaEngine::default() - }, + media_engine: self.media_engine.take().unwrap_or_default(), /*TODO:interceptor_registry: if let Some(interceptor_registry) = self.interceptor_registry.take() { diff --git a/rtc/src/peer_connection/configuration.rs b/rtc/src/peer_connection/configuration.rs index 7e19b58..521cbbe 100644 --- a/rtc/src/peer_connection/configuration.rs +++ b/rtc/src/peer_connection/configuration.rs @@ -48,6 +48,7 @@ impl RTCConfiguration { /// get_ice_servers side-steps the strict parsing mode of the ice package /// (as defined in https://tools.ietf.org/html/rfc7064) by copying and then /// stripping any erroneous queries from "stun(s):" URLs before parsing. + #[allow(clippy::assigning_clones)] pub(crate) fn get_ice_servers(&self) -> Vec { let mut ice_servers = self.ice_servers.clone(); diff --git a/rtc/src/peer_connection/mod.rs b/rtc/src/peer_connection/mod.rs index 8927233..c610178 100644 --- a/rtc/src/peer_connection/mod.rs +++ b/rtc/src/peer_connection/mod.rs @@ -878,7 +878,7 @@ impl RTCPeerConnection { parsed: Some(d), }; - self.last_offer = offer.sdp.clone(); + self.last_offer.clone_from(&offer.sdp); Ok(offer) } @@ -924,7 +924,7 @@ impl RTCPeerConnection { parsed: Some(d), }; - self.last_answer = answer.sdp.clone(); + self.last_answer.clone_from(&answer.sdp); Ok(answer) } @@ -1199,10 +1199,10 @@ impl RTCPeerConnection { if desc.sdp.is_empty() { match desc.sdp_type { RTCSdpType::Answer | RTCSdpType::Pranswer => { - desc.sdp = self.last_answer.clone(); + desc.sdp.clone_from(&self.last_answer); } RTCSdpType::Offer => { - desc.sdp = self.last_offer.clone(); + desc.sdp.clone_from(&self.last_offer); } _ => return Err(Error::ErrPeerConnSDPTypeInvalidValueSetLocalDescription), } diff --git a/rtc/src/peer_connection/sdp/mod.rs b/rtc/src/peer_connection/sdp/mod.rs index bf47d39..0efcd37 100644 --- a/rtc/src/peer_connection/sdp/mod.rs +++ b/rtc/src/peer_connection/sdp/mod.rs @@ -261,7 +261,7 @@ pub(crate) fn get_rids(media: &MediaDescription) -> Vec { log::warn!("Failed to parse RID: {}", err); } } else if attr.key.as_str() == SDP_ATTRIBUTE_SIMULCAST { - simulcast_attr = attr.value.clone(); + simulcast_attr.clone_from(&attr.value); } } diff --git a/rtc/src/transport/ice_transport/ice_server.rs b/rtc/src/transport/ice_transport/ice_server.rs index 79bd5fa..9d6f680 100644 --- a/rtc/src/transport/ice_transport/ice_server.rs +++ b/rtc/src/transport/ice_transport/ice_server.rs @@ -34,12 +34,12 @@ impl RTCIceServer { if self.username.is_empty() || self.credential.is_empty() { return Err(Error::ErrNoTurnCredentials); } - url.username = self.username.clone(); + url.username.clone_from(&self.username); match self.credential_type { RTCIceCredentialType::Password => { // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.3) - url.password = self.credential.clone(); + url.password.clone_from(&self.credential); } _ => return Err(Error::ErrTurnCredentials), };