Apply clippy lints

This commit is contained in:
QuantumEntangledAndy committed 2022-06-21 10:29:06 +07:00
1 parent f375d1b14d
commit 11a4ec921d
9 files changed
+13 -15

No files matched your search

+4 -5
View File
@@ -169,8 +169,7 @@ fn bc_modern_msg<'a, 'b>(
};
// Now we'll take the buffer that Nom gave a ref to and parse it.
let extension;
if ext_len > 0 {
let extension = if ext_len > 0 {
// Apply the XML parse function, but throw away the reference to decrypted in the Ok and
// Err case. This error-error-error thing is the same idiom Nom uses internally.
let parsed = Extension::try_parse(processed_ext_buf)
@@ -182,10 +181,10 @@ fn bc_modern_msg<'a, 'b>(
{
context.in_bin_mode.insert(header.msg_num);
}
extension = Some(parsed);
Some(parsed)
} else {
extension = None;
}
None
};
// Now to handle the payload block
// This block can either be xml or binary depending on what the message expects.
+1 -1
View File
@@ -173,7 +173,7 @@ where
/// A serializer combinator that does nothing with its input
fn do_nothing<W>() -> impl SerializeFn<W> {
move |out: WriteContext<W>| Ok(out)
Ok
}
#[test]
+1
View File
@@ -12,6 +12,7 @@ use indoc::indoc;
/// There are two types of payloads xml and binary
#[derive(PartialEq, Eq, Debug, YaDeserialize)]
#[yaserde(flatten)]
#[allow(clippy::large_enum_variant)]
pub enum BcPayloads {
/// XML payloads are the more common ones and include payloads for camera controls
#[yaserde(rename = "body")]
@@ -40,12 +40,11 @@ impl UdpDiscover {
let addrs: Vec<SocketAddr> = addrs
.iter()
.map(|a| {
.flat_map(|a| {
a.to_socket_addrs()
.ok()
.and_then(|mut a_iter| a_iter.next())
})
.flatten()
.collect();
let mut bytes_send = 0;
@@ -120,13 +119,12 @@ impl UdpDiscover {
let ports: [u16; 2] = [2015, 2018];
let destinations: Vec<(Ipv4Addr, u16)> = broadcasts
.iter()
.map(|&addr| {
.flat_map(|&addr| {
ports
.iter()
.map(|&port| (addr, port))
.collect::<Vec<(Ipv4Addr, u16)>>()
})
.flatten()
.collect();
debug!("Broadcasting to: {:?}", destinations);
+1 -1
View File
@@ -87,7 +87,7 @@ where
impl BcMedia {
pub(crate) fn deserialize<R: Read>(r: R) -> Result<BcMedia, Error> {
// Throw away the nom-specific return types
read_from_reader(|reader| bcmedia(reader), r)
read_from_reader(bcmedia, r)
}
}
+1 -1
View File
@@ -84,7 +84,7 @@ where
impl BcUdp {
pub(crate) fn deserialize<R: Read>(r: R) -> Result<BcUdp, Error> {
// Throw away the nom-specific return types
read_from_reader(|reader| bcudp(reader), r)
read_from_reader(bcudp, r)
}
}
+1
View File
@@ -5,6 +5,7 @@ use super::xml::*;
/// Top level udp packet
#[derive(Debug, PartialEq, Eq)]
#[allow(clippy::large_enum_variant)]
pub enum BcUdp {
/// Packet from the negotiate stage when connection info is exchanged
Discovery(UdpDiscovery),
+1 -2
View File
@@ -5,8 +5,7 @@ const XML_KEY: [u32; 8] = [
pub(crate) fn decrypt(offset: u32, buf: &[u8]) -> Vec<u8> {
let key = XML_KEY
.iter()
.map(|i| (i + offset).to_le_bytes())
.flatten()
.flat_map(|i| (i + offset).to_le_bytes())
.cycle();
buf.iter().zip(key).map(|(byte, key)| key ^ byte).collect()
}
+1 -1
View File
@@ -347,7 +347,7 @@ mod maybe_app_src {
/// owning the AppSrc directly. This function handles either case and returns the AppSrc,
/// or None if the caller has not yet sent one.
fn try_get_src(&mut self) -> Option<&AppSrc> {
while let Some(src) = self.rx.try_recv().ok() {
while let Ok(src) = self.rx.try_recv() {
self.app_src = Some(src);
}
self.app_src.as_ref()