diff --git a/.github/workflows/style_checks.yml b/.github/workflows/style_checks.yml index f1f0d1f..6d10914 100644 --- a/.github/workflows/style_checks.yml +++ b/.github/workflows/style_checks.yml @@ -17,10 +17,16 @@ jobs: toolchain: nightly components: clippy override: true - - uses: actions-rs/clippy-check@v1 + - name: Run clippy action to produce annotations + uses: actions-rs/clippy-check@v1 + if: steps.check_permissions.outputs.has-permission with: + toolchain: nightly token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features + args: --workspace --all-targets --all-features + - name: Run clippy manually without annotations + if: ${{ !steps.check_permissions.outputs.has-permission }} + run: cargo +nightly clippy --workspace --all-targets --all-features check_fmt: name: Rust-fmt diff --git a/crates/core/src/bc/de.rs b/crates/core/src/bc/de.rs index 0d88354..5c0d9af 100644 --- a/crates/core/src/bc/de.rs +++ b/crates/core/src/bc/de.rs @@ -245,7 +245,7 @@ fn test_bc_modern_login() { })), .. }) => assert_eq!(encryption.nonce, "9E6D1FCB9E69846D"), - _ => assert!(false), + _ => panic!(), } } @@ -271,7 +271,7 @@ fn test_bc_legacy_login() { assert_eq!(username, "21232F297A57A5A743894A0E4A801FC\0"); assert_eq!(password, EMPTY_LEGACY_PASSWORD); } - _ => assert!(false), + _ => panic!(), } } @@ -296,10 +296,8 @@ fn test_bc_modern_login_failed() { BcBody::ModernMsg(ModernMsg { extension: None, payload: None, - }) => { - assert!(true); - } - _ => assert!(false), + }) => {} + _ => panic!(), } } @@ -327,8 +325,8 @@ fn test_bc_modern_login_success() { BcBody::ModernMsg(ModernMsg { extension: None, payload: Some(_), - }) => assert!(true), - _ => assert!(false), + }) => {} + _ => panic!(), } } @@ -353,7 +351,7 @@ fn test_bc_binary_mode() { }) => { assert_eq!(bin.len(), 32); } - _ => assert!(false), + _ => panic!(), } context.in_bin_mode.insert(msg1.meta.msg_num); @@ -365,6 +363,6 @@ fn test_bc_binary_mode() { }) => { assert_eq!(bin.len(), 30344); } - _ => assert!(false), + _ => panic!(), } } diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index 85f3e27..ac027d7 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -209,8 +209,8 @@ fn test_encryption_deser() { let t = BcXml::try_parse(sample.as_bytes()).unwrap(); match t { - top_b if top_b == b => assert!(true), - _ => assert!(false), + top_b if top_b == b => {}, + _ => panic!(), } } @@ -327,8 +327,8 @@ fn test_deviceinfo_partial_deser() { .. }), .. - } => assert!(true), - _ => assert!(false), + } => {}, + _ => panic!(), } } @@ -349,7 +349,7 @@ fn test_binary_deser() { Extension { binary_data: Some(1), .. - } => assert!(true), - _ => assert!(false), + } => {}, + _ => panic!(), } } diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs index 7b036d0..c0579ef 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -6,8 +6,7 @@ use adpcm::adpcm_to_pcm; use err_derive::Error; use log::*; use std::convert::TryInto; -use std::io::Write; -use std::net::{SocketAddr, ToSocketAddrs}; +use std::net::ToSocketAddrs; use std::sync::atomic::{AtomicU16, Ordering}; use std::time::Duration; @@ -28,13 +27,13 @@ const RX_TIMEOUT: Duration = Duration::from_secs(5); #[allow(clippy::large_enum_variant)] pub enum Error { #[error(display = "Communication error")] - CommunicationError(#[error(source)] std::io::Error), + Communication(#[error(source)] std::io::Error), #[error(display = "Deserialization error")] - DeserializationError(#[error(source)] bc::de::Error), + Deserialization(#[error(source)] bc::de::Error), #[error(display = "Serialization error")] - SerializationError(#[error(source)] bc::ser::Error), + Serialization(#[error(source)] bc::ser::Error), #[error(display = "Connection error")] ConnectionError(#[error(source)] self::connection::Error), @@ -74,7 +73,6 @@ impl<'a> From for Error { } pub struct BcCamera { - address: SocketAddr, channel_id: u8, connection: Option, logged_in: bool, @@ -114,7 +112,7 @@ impl BcCamera { let conn = match BcConnection::new(addr, RX_TIMEOUT) { Ok(conn) => conn, Err(err) => match err { - connection::Error::CommunicationError(ref err) => { + connection::Error::Communication(ref err) => { debug!("Assuming timeout from {}", err); continue; } @@ -124,7 +122,6 @@ impl BcCamera { debug!("Success: {}", addr); return Ok(Self { - address: addr, connection: Some(conn), message_num: AtomicU16::new(0), channel_id, diff --git a/crates/core/src/bc_protocol/adpcm.rs b/crates/core/src/bc_protocol/adpcm.rs index a42b0cd..2daf613 100644 --- a/crates/core/src/bc_protocol/adpcm.rs +++ b/crates/core/src/bc_protocol/adpcm.rs @@ -14,6 +14,7 @@ struct AdpcmSetup { impl AdpcmSetup { // Unused, originally we thought BC might be using OKI but it is actually DVI4 + #[allow(dead_code)] fn new_oki() -> Self { Self { max_step_index: 48, @@ -57,10 +58,12 @@ impl Nibble { (self.data & 0b00001111) as u32 // Mask first 4 bits it just to be sure its in nibble range } + #[allow(dead_code)] fn signed_magnitude(&self) -> u32 { (self.data & 0b00000111) as u32 // Mask of first 3 bits which are the magnitiude bits in signed int } + #[allow(dead_code)] fn signed(&self) -> i32 { match self.data & 0b00001000 { // Sign bit is at the 4th bit diff --git a/crates/core/src/bc_protocol/connection.rs b/crates/core/src/bc_protocol/connection.rs index 44c30a2..467b2a5 100644 --- a/crates/core/src/bc_protocol/connection.rs +++ b/crates/core/src/bc_protocol/connection.rs @@ -37,13 +37,13 @@ type Result = std::result::Result; #[derive(Debug, Error)] pub enum Error { #[error(display = "Communication error")] - CommunicationError(#[error(source)] std::io::Error), + Communication(#[error(source)] std::io::Error), #[error(display = "Deserialization error")] - DeserializationError(#[error(source)] bc::de::Error), + Deserialization(#[error(source)] bc::de::Error), #[error(display = "Serialization error")] - SerializationError(#[error(source)] bc::ser::Error), + Serialization(#[error(source)] bc::ser::Error), #[error(display = "Simultaneous subscription")] SimultaneousSubscription { msg_id: u32 }, diff --git a/crates/core/src/bc_protocol/media_packet.rs b/crates/core/src/bc_protocol/media_packet.rs index 8f35f09..abf8ba2 100644 --- a/crates/core/src/bc_protocol/media_packet.rs +++ b/crates/core/src/bc_protocol/media_packet.rs @@ -52,10 +52,14 @@ impl MediaData { MediaData::header_size_from_kind(kind) } + // Unused was part of debug code + #[allow(dead_code)] pub fn header(&self) -> &[u8] { &self.data[0..self.header_size()] } + // Unused was part of debug code + #[allow(dead_code)] pub fn header_dump(&self) { info!("{:?}-hex: {:02?}", self.kind(), self.header()); let mut result = vec![]; @@ -184,6 +188,8 @@ impl MediaData { } } + // Unused. TODO: Use this to time stamp video streams correctly + #[allow(dead_code)] pub fn timestamp(&self) -> Option { let kind = self.kind(); match kind { diff --git a/crates/core/src/bc_protocol/time.rs b/crates/core/src/bc_protocol/time.rs index 2e1e7d2..a725063 100644 --- a/crates/core/src/bc_protocol/time.rs +++ b/crates/core/src/bc_protocol/time.rs @@ -46,7 +46,7 @@ impl BcCamera { let datetime = match try_build_timestamp(time_zone, year, month, day, hour, minute, second) { Ok(dt) => dt, - Err(e) => { + Err(_) => { return Err(Error::UnintelligibleReply { reply: msg, why: "Could not parse date", @@ -110,7 +110,7 @@ impl BcCamera { ); sub_set_general.send(set)?; - let msg = sub_set_general.rx.recv_timeout(RX_TIMEOUT)?; + let _ = sub_set_general.rx.recv_timeout(RX_TIMEOUT)?; Ok(()) } diff --git a/crates/rtsp/src/gst.rs b/crates/rtsp/src/gst.rs index f8d3eca..9ae3245 100644 --- a/crates/rtsp/src/gst.rs +++ b/crates/rtsp/src/gst.rs @@ -14,7 +14,7 @@ use gstreamer_rtsp_server::{ RTSP_TOKEN_MEDIA_FACTORY_ROLE, }; use log::*; -use neolink_core::bc_protocol::{Error, StreamFormat, StreamOutput, StreamOutputError}; +use neolink_core::bc_protocol::{StreamFormat, StreamOutput, StreamOutputError}; use std::collections::HashSet; use std::fs; use std::io; diff --git a/crates/rtsp/src/lib.rs b/crates/rtsp/src/lib.rs index 2850538..7f9a7f7 100644 --- a/crates/rtsp/src/lib.rs +++ b/crates/rtsp/src/lib.rs @@ -27,9 +27,9 @@ pub fn main(opt: Opt) -> Result<(), Error> { let rtsp = &RtspServer::new(); - set_up_tls(&config, &rtsp); + set_up_tls(&config, rtsp); - set_up_users(&config.users, &rtsp); + set_up_users(&config.users, rtsp); if config.certificate == None && !config.users.is_empty() { warn!( @@ -132,7 +132,7 @@ fn set_up_tls(config: &Config, rtsp: &RtspServer) { _ => unreachable!(), }; if let Some(cert_path) = &config.certificate { - rtsp.set_tls(&cert_path, tls_client_auth) + rtsp.set_tls(cert_path, tls_client_auth) .expect("Failed to set up TLS"); } }