From 8f82bb7fbcb024a5124faa83ee424978e9741894 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Sat, 4 Jul 2020 12:26:30 -0500 Subject: [PATCH] Use a few Rust idioms --- src/config.rs | 2 ++ src/main.rs | 14 +++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0a230c4..5ee198b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,9 +1,11 @@ +use lazy_static::lazy_static; use regex::Regex; use serde::Deserialize; use std::clone::Clone; use std::net::SocketAddr; use std::time::Duration; use validator::Validate; +use validator_derive::Validate; lazy_static! { static ref RE_STREAM_FORM: Regex = Regex::new(r"^([hH]26[45]|[ \t]*[!].*)$").unwrap(); diff --git a/src/main.rs b/src/main.rs index 161509a..f0620ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,3 @@ -#[macro_use] -extern crate validator_derive; -#[macro_use] -extern crate lazy_static; - use env_logger::Env; use err_derive::Error; use log::*; @@ -46,10 +41,7 @@ fn main() -> Result<(), Error> { let opt = Opt::from_args(); let config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?; - match config.validate() { - Ok(_) => (), - Err(e) => return Err(Error::ValidationError(e)), - }; + config.validate()?; let rtsp = &RtspServer::new(); @@ -73,7 +65,7 @@ fn main() -> Result<(), Error> { let arc_cam = Arc::new(camera); // Set up each main and substream according to all the RTSP mount paths we support - if arc_cam.stream == "both" || arc_cam.stream == "mainStream" { + if ["both", "mainStream"].iter().any(|&e| e == arc_cam.stream) { let paths = &[ &*format!("/{}", arc_cam.name), &*format!("/{}/mainStream", arc_cam.name), @@ -82,7 +74,7 @@ fn main() -> Result<(), Error> { let main_camera = arc_cam.clone(); s.spawn(move |_| camera_loop(&*main_camera, "mainStream", &mut output)); } - if arc_cam.stream == "both" || arc_cam.stream == "subStream" { + if ["both", "subStream"].iter().any(|&e| e == arc_cam.stream) { let paths = &[&*format!("/{}/subStream", arc_cam.name)]; let mut output = rtsp.add_stream(paths, &substream_format).unwrap(); let sub_camera = arc_cam.clone();