Add clippy and fmt checks and conform to clippy style

This commit is contained in:
QuantumEntangledAndy authored and George Hilliard committed 2020-09-17 09:38:27 -05:00
1 parent fab6a11820
commit b0eee39f13
8 files changed
+56 -11

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
name: Style
on: [push, pull_request]
jobs:
check_clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
check_fmt:
name: Rust-fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt
override: true
- name: rustfmt
run: |
cargo +nightly fmt -- --check
+1
View File
@@ -0,0 +1 @@
enum-variant-size-threshold = 700
+2 -2
View File
@@ -99,14 +99,14 @@ fn hex32<'a>() -> impl Fn(&'a [u8]) -> IResult<&'a [u8], String> {
})
}
fn bc_legacy_login_msg<'a, 'b>(buf: &'b [u8]) -> IResult<&'b [u8], LegacyMsg> {
fn bc_legacy_login_msg<'a>(buf: &'a [u8]) -> IResult<&'a [u8], LegacyMsg> {
let (buf, username) = hex32()(buf)?;
let (buf, password) = hex32()(buf)?;
Ok((buf, LegacyMsg::LoginMsg { username, password }))
}
fn bc_modern_msg<'a, 'b, 'c>(
fn bc_modern_msg<'a, 'b>(
context: &mut BcContext,
header: &'a BcHeader,
buf: &'b [u8],
+6
View File
@@ -83,6 +83,12 @@ impl Bc {
}
}
impl Default for BcContext {
fn default() -> BcContext {
Self::new()
}
}
impl BcContext {
pub fn new() -> BcContext {
BcContext {
+1 -2
View File
@@ -4,7 +4,6 @@ use crate::bc;
use crate::bc::{model::*, xml::*};
use err_derive::Error;
use log::*;
use md5;
use std::io::Write;
use std::net::{SocketAddr, ToSocketAddrs};
use std::time::Duration;
@@ -111,7 +110,7 @@ impl BcCamera {
let md5_username = md5_string(username, ZeroLast);
let md5_password = password
.map(|p| md5_string(p, ZeroLast))
.unwrap_or(EMPTY_LEGACY_PASSWORD.to_owned());
.unwrap_or_else(|| EMPTY_LEGACY_PASSWORD.to_owned());
let legacy_login = Bc {
meta: BcMeta {
+2 -2
View File
@@ -55,7 +55,7 @@ impl BcConnection {
let rx_thread = std::thread::spawn(move || {
let mut context = BcContext::new();
while let Ok(_) = BcConnection::poll(&mut context, &conn, &mut subs) {}
while BcConnection::poll(&mut context, &conn, &mut subs).is_ok() {}
});
Ok(BcConnection {
@@ -96,7 +96,7 @@ impl BcConnection {
let mut locked_subs = subscribers.lock().unwrap();
match locked_subs.entry(msg_id) {
Entry::Occupied(mut occ) => {
if let Err(_) = occ.get_mut().send(response) {
if occ.get_mut().send(response).is_err() {
// Exceedingly unlikely, unless you mishandle the subscription object
warn!("Subscriber to ID {} dropped their channel", msg_id);
occ.remove();
+8 -2
View File
@@ -33,6 +33,12 @@ pub enum StreamFormat {
Custom(String),
}
impl Default for RtspServer {
fn default() -> RtspServer {
Self::new()
}
}
impl RtspServer {
pub fn new() -> RtspServer {
gstreamer::init().expect("Gstreamer should not explode");
@@ -144,7 +150,7 @@ impl RtspServer {
}
pub fn set_credentials(&self, credentials: &[(&str, &str)]) -> Result<()> {
let auth = self.server.get_auth().unwrap_or_else(|| RTSPAuth::new());
let auth = self.server.get_auth().unwrap_or_else(RTSPAuth::new);
auth.set_supported_methods(RTSPAuthMethod::Basic);
let mut un_authtoken = RTSPToken::new(&[(*RTSP_TOKEN_MEDIA_FACTORY_ROLE, &"anonymous")]);
@@ -164,7 +170,7 @@ impl RtspServer {
pub fn set_tls(&self, cert_file: &str, client_auth: TlsAuthenticationMode) -> Result<()> {
debug!("Setting up TLS using {}", cert_file);
let auth = self.server.get_auth().unwrap_or_else(|| RTSPAuth::new());
let auth = self.server.get_auth().unwrap_or_else(RTSPAuth::new);
// We seperate reading the file and changing to a PEM so that we get different error messages.
let cert_contents = fs::read_to_string(cert_file).expect("TLS file not found");
+3 -3
View File
@@ -62,7 +62,7 @@ fn main() -> Result<(), Error> {
let stream_format = match &*camera.format {
"h264" | "H264" => StreamFormat::H264,
"h265" | "H265" => StreamFormat::H265,
custom_format @ _ => StreamFormat::Custom(custom_format.to_string()),
custom_format => StreamFormat::Custom(custom_format.to_string()),
};
// Let subthreads share the camera object; in principle I think they could share
@@ -73,7 +73,7 @@ fn main() -> Result<(), Error> {
// The substream always seems to be H264, even on B800 cameras
let substream_format = match &*arc_cam.format {
"h264" | "H264" | "h265" | "H265" => StreamFormat::H264,
custom_format @ _ => StreamFormat::Custom(custom_format.to_string()),
custom_format => StreamFormat::Custom(custom_format.to_string()),
};
let permitted_users =
get_permitted_users(config.users.as_slice(), &arc_cam.permitted_users);
@@ -205,7 +205,7 @@ fn camera_main(
let mut connected = false;
(|| {
let mut camera = BcCamera::new_with_addr(camera_config.camera_addr)?;
if let Some(_) = camera_config.timeout {
if camera_config.timeout.is_some() {
warn!("The undocumented `timeout` config option has been removed and is no longer needed.");
warn!("Please update your config file.");
}