From f88c02a7aab0ad204c185861414db83449a162a7 Mon Sep 17 00:00:00 2001 From: Valmo Date: Tue, 24 Mar 2026 16:44:22 -0300 Subject: [PATCH] formatted some rust files for linting porpuses --- src/cot/cot.rs | 2 +- src/cot/digital_pointer.rs | 70 +++++++-------- src/cot/draws/mod.rs | 2 +- src/cot/eud.rs | 104 +++++++++++------------ src/cot/gps.rs | 82 +++++++++--------- src/cot/message.rs | 18 ++-- src/cot/mod.rs | 4 +- src/structs.rs | 5 +- src/tcp/cot.rs | 15 +++- src/tcp/draw.rs | 23 ++--- src/tests.rs | 34 ++++---- src/udp_socket.rs | 169 +++++++++++++++++++------------------ src/utils/address.rs | 34 ++++---- src/utils/log.rs | 16 ++-- src/utils/mod.rs | 4 +- src/utils/uuid.rs | 6 +- src/video_stream.rs | 32 ++++--- 17 files changed, 317 insertions(+), 303 deletions(-) diff --git a/src/cot/cot.rs b/src/cot/cot.rs index a9ce413..c749e66 100644 --- a/src/cot/cot.rs +++ b/src/cot/cot.rs @@ -1,5 +1,5 @@ -use uuid::Uuid; use chrono::{Duration, SecondsFormat, Utc}; +use uuid::Uuid; pub struct CursorOverTime { pub uuid: Option, diff --git a/src/cot/digital_pointer.rs b/src/cot/digital_pointer.rs index 2ea3064..2b73a4d 100644 --- a/src/cot/digital_pointer.rs +++ b/src/cot/digital_pointer.rs @@ -1,45 +1,45 @@ -use arma_rs::{FromArma, FromArmaError}; use super::cot::CursorOverTime; +use arma_rs::{FromArma, FromArmaError}; pub struct DigitalPointerPayload { - pub link_uid: String, - pub contact_callsign: String, - pub point_lat: f64, - pub point_lon: f64, - pub point_hae: f32, + pub link_uid: String, + pub contact_callsign: String, + pub point_lat: f64, + pub point_lon: f64, + pub point_hae: f32, } impl FromArma for DigitalPointerPayload { - fn from_arma(data: String) -> Result { - let (link_uid, contact_callsign, point_lat, point_lon, point_hae) = - <(String, String, f64, f64, f32)>::from_arma(data)?; - Ok(Self { - link_uid, - contact_callsign, - point_lat, - point_lon, - point_hae, - }) - } + fn from_arma(data: String) -> Result { + let (link_uid, contact_callsign, point_lat, point_lon, point_hae) = + <(String, String, f64, f64, f32)>::from_arma(data)?; + Ok(Self { + link_uid, + contact_callsign, + point_lat, + point_lon, + point_hae, + }) + } } impl DigitalPointerPayload { - pub fn to_cot(&self) -> CursorOverTime { - CursorOverTime { - uuid: Some(format!("{}{}", self.link_uid.clone(), ".SPI1")), - r#type: Some("b-m-p-s-p-i".to_string()), - point_lat: self.point_lat, - point_lon: self.point_lon, - point_hae: self.point_hae, - point_ce: None, - point_le: None, - contact_callsign: self.contact_callsign.clone(), - group_name: None, - group_role: None, - track_course: None, - track_speed: None, - link_uid: Some(self.link_uid.clone()), - remarker: None, - } - } + pub fn to_cot(&self) -> CursorOverTime { + CursorOverTime { + uuid: Some(format!("{}{}", self.link_uid.clone(), ".SPI1")), + r#type: Some("b-m-p-s-p-i".to_string()), + point_lat: self.point_lat, + point_lon: self.point_lon, + point_hae: self.point_hae, + point_ce: None, + point_le: None, + contact_callsign: self.contact_callsign.clone(), + group_name: None, + group_role: None, + track_course: None, + track_speed: None, + link_uid: Some(self.link_uid.clone()), + remarker: None, + } + } } diff --git a/src/cot/draws/mod.rs b/src/cot/draws/mod.rs index 44ca87b..0241c06 100644 --- a/src/cot/draws/mod.rs +++ b/src/cot/draws/mod.rs @@ -1 +1 @@ -pub mod circle; \ No newline at end of file +pub mod circle; diff --git a/src/cot/eud.rs b/src/cot/eud.rs index 5d3cae9..50e01fa 100644 --- a/src/cot/eud.rs +++ b/src/cot/eud.rs @@ -1,62 +1,62 @@ -use arma_rs::{FromArma, FromArmaError}; use super::cot::CursorOverTime; +use arma_rs::{FromArma, FromArmaError}; pub struct EudCoTPayload { - pub uuid: String, - pub point_lat: f64, - pub point_lon: f64, - pub point_hae: f32, - pub contact_callsign: String, - pub group_name: String, - pub group_role: String, - pub track_course: i32, - pub track_speed: f32, + pub uuid: String, + pub point_lat: f64, + pub point_lon: f64, + pub point_hae: f32, + pub contact_callsign: String, + pub group_name: String, + pub group_role: String, + pub track_course: i32, + pub track_speed: f32, } impl FromArma for EudCoTPayload { - fn from_arma(data: String) -> Result { - let ( - uuid, - point_lat, - point_lon, - point_hae, - contact_callsign, - group_name, - group_role, - track_course, - track_speed, - ) = <(String, f64, f64, f32, String, String, String, i32, f32)>::from_arma(data)?; - Ok(Self { - uuid, - point_lat, - point_lon, - point_hae, - contact_callsign, - group_name, - group_role, - track_course, - track_speed, - }) - } + fn from_arma(data: String) -> Result { + let ( + uuid, + point_lat, + point_lon, + point_hae, + contact_callsign, + group_name, + group_role, + track_course, + track_speed, + ) = <(String, f64, f64, f32, String, String, String, i32, f32)>::from_arma(data)?; + Ok(Self { + uuid, + point_lat, + point_lon, + point_hae, + contact_callsign, + group_name, + group_role, + track_course, + track_speed, + }) + } } impl EudCoTPayload { - pub fn to_cot(&self) -> CursorOverTime { - CursorOverTime { - uuid: Some(self.uuid.clone()), - r#type: None, - point_lat: self.point_lat, - point_lon: self.point_lon, - point_hae: self.point_hae, - point_ce: None, - point_le: None, - contact_callsign: self.contact_callsign.clone(), - group_name: Some(self.group_name.clone()), - group_role: Some(self.group_role.clone()), - track_course: Some(self.track_course), - track_speed: Some(self.track_speed), - link_uid: None, - remarker: None, - } - } + pub fn to_cot(&self) -> CursorOverTime { + CursorOverTime { + uuid: Some(self.uuid.clone()), + r#type: None, + point_lat: self.point_lat, + point_lon: self.point_lon, + point_hae: self.point_hae, + point_ce: None, + point_le: None, + contact_callsign: self.contact_callsign.clone(), + group_name: Some(self.group_name.clone()), + group_role: Some(self.group_role.clone()), + track_course: Some(self.track_course), + track_speed: Some(self.track_speed), + link_uid: None, + remarker: None, + } + } } diff --git a/src/cot/gps.rs b/src/cot/gps.rs index d952de1..fa70c8f 100644 --- a/src/cot/gps.rs +++ b/src/cot/gps.rs @@ -1,5 +1,5 @@ -use arma_rs::{FromArma, FromArmaError}; use super::cot::CursorOverTime; +use arma_rs::{FromArma, FromArmaError}; pub struct ExternalPositionPayload { pub uuid: String, @@ -13,47 +13,47 @@ pub struct ExternalPositionPayload { } impl FromArma for ExternalPositionPayload { - fn from_arma(data: String) -> Result { - let ( - uuid, - point_lat, - point_lon, - point_hae, - contact_callsign, - track_course, - track_speed, - remarker, - ) = <(String, f64, f64, f32, String, i32, f32, String)>::from_arma(data)?; - Ok(Self { - uuid, - point_lat, - point_lon, - point_hae, - contact_callsign, - track_course, - track_speed, - remarker, - }) - } + fn from_arma(data: String) -> Result { + let ( + uuid, + point_lat, + point_lon, + point_hae, + contact_callsign, + track_course, + track_speed, + remarker, + ) = <(String, f64, f64, f32, String, i32, f32, String)>::from_arma(data)?; + Ok(Self { + uuid, + point_lat, + point_lon, + point_hae, + contact_callsign, + track_course, + track_speed, + remarker, + }) + } } impl ExternalPositionPayload { - pub fn to_cot(&self) -> CursorOverTime { - CursorOverTime { - uuid: Some(self.uuid.clone()), - r#type: None, - point_lat: self.point_lat, - point_lon: self.point_lon, - point_hae: self.point_hae, - point_ce: None, - point_le: None, - contact_callsign: self.contact_callsign.clone(), - group_name: None, - group_role: None, - track_course: Some(self.track_course), - track_speed: Some(self.track_speed), - link_uid: None, - remarker: Some(self.remarker.clone()), - } - } + pub fn to_cot(&self) -> CursorOverTime { + CursorOverTime { + uuid: Some(self.uuid.clone()), + r#type: None, + point_lat: self.point_lat, + point_lon: self.point_lon, + point_hae: self.point_hae, + point_ce: None, + point_le: None, + contact_callsign: self.contact_callsign.clone(), + group_name: None, + group_role: None, + track_course: Some(self.track_course), + track_speed: Some(self.track_speed), + link_uid: None, + remarker: Some(self.remarker.clone()), + } + } } diff --git a/src/cot/message.rs b/src/cot/message.rs index 84b4c84..2846d49 100644 --- a/src/cot/message.rs +++ b/src/cot/message.rs @@ -1,5 +1,5 @@ use arma_rs::{FromArma, FromArmaError}; -use chrono::{Utc, Duration, SecondsFormat}; +use chrono::{Duration, SecondsFormat, Utc}; use uuid::Uuid; pub struct MessagePayload { @@ -14,8 +14,7 @@ pub struct MessagePayload { impl FromArma for MessagePayload { fn from_arma(data: String) -> Result { - let (sender_callsign, chatroom, message_text, - point_lat, point_lon, point_hae, sender_uid) = + let (sender_callsign, chatroom, message_text, point_lat, point_lon, point_hae, sender_uid) = <(String, String, String, f64, f64, f32, String)>::from_arma(data)?; Ok(Self { @@ -55,8 +54,8 @@ impl MessageCot { pub fn to_xml(&self) -> String { let created_time = Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true); - let stale_time = (Utc::now() + Duration::days(1)) - .to_rfc3339_opts(SecondsFormat::Millis, true); + let stale_time = + (Utc::now() + Duration::days(1)).to_rfc3339_opts(SecondsFormat::Millis, true); // MESSAGE ID (random UUID) let message_uuid = Uuid::new_v4().to_string(); @@ -98,10 +97,7 @@ impl MessageCot { format!( "<__chat parent=\"RootContactGroup\" groupOwner=\"false\" \ messageId=\"{}\" chatroom=\"{}\" id=\"{}\" senderCallsign=\"{}\">", - message_uuid, - self.chatroom, - self.chatroom, - self.sender_callsign, + message_uuid, self.chatroom, self.chatroom, self.sender_callsign, ) .as_str(), ); @@ -109,9 +105,7 @@ impl MessageCot { xml.push_str( format!( "", - self.sender_uid, - self.chatroom, - self.chatroom + self.sender_uid, self.chatroom, self.chatroom ) .as_str(), ); diff --git a/src/cot/mod.rs b/src/cot/mod.rs index 6c8ca30..1f23edf 100644 --- a/src/cot/mod.rs +++ b/src/cot/mod.rs @@ -1,7 +1,7 @@ -pub mod draws; pub mod cot; pub mod digital_pointer; +pub mod draws; pub mod eud; pub mod gps; pub mod message; -pub mod nato; \ No newline at end of file +pub mod nato; diff --git a/src/structs.rs b/src/structs.rs index 9d51610..0e70b4b 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -10,9 +10,6 @@ pub struct LogPayload { impl FromArma for LogPayload { fn from_arma(data: String) -> Result { let (status, message) = <(String, String)>::from_arma(data)?; - Ok(Self { - status, - message - }) + Ok(Self { status, message }) } } diff --git a/src/tcp/cot.rs b/src/tcp/cot.rs index c5086bc..a61a82f 100644 --- a/src/tcp/cot.rs +++ b/src/tcp/cot.rs @@ -9,21 +9,30 @@ pub fn send_eud_cot(ctx: Context, cursor_over_time: cot::eud::EudCoTPayload) -> "Sending End User Device Cursor Over Time to TCP server" } -pub fn send_marker_cot(ctx: Context, cursor_over_time: cot::nato::MarkerCoTPayload) -> &'static str { +pub fn send_marker_cot( + ctx: Context, + cursor_over_time: cot::nato::MarkerCoTPayload, +) -> &'static str { let payload = cursor_over_time.to_cot().convert_to_xml(); send_payload(ctx, payload); "Sending Marker Cursor Over Time to TCP server" } -pub fn send_digital_pointer_cot(ctx: Context, cursor_over_time: cot::digital_pointer::DigitalPointerPayload) -> &'static str { +pub fn send_digital_pointer_cot( + ctx: Context, + cursor_over_time: cot::digital_pointer::DigitalPointerPayload, +) -> &'static str { let payload = cursor_over_time.to_cot().convert_to_xml(); send_payload(ctx, payload); "Sending Digital Pointer Cursor Over Time to TCP server" } -pub fn send_message_cot(ctx: Context, message_payload: cot::message::MessagePayload) -> &'static str { +pub fn send_message_cot( + ctx: Context, + message_payload: cot::message::MessagePayload, +) -> &'static str { let message_cot = cot::message::MessageCot::from_payload(message_payload); let payload = message_cot.to_xml(); send_payload(ctx, payload); diff --git a/src/tcp/draw.rs b/src/tcp/draw.rs index c3f859b..c52fb2c 100644 --- a/src/tcp/draw.rs +++ b/src/tcp/draw.rs @@ -2,7 +2,10 @@ use arma_rs::Context; use crate::{cot, tcp::send_payload}; -pub fn send_circle_cot(ctx: Context, circle_payload: cot::draws::circle::CircleCoTPayload) -> &'static str { +pub fn send_circle_cot( + ctx: Context, + circle_payload: cot::draws::circle::CircleCoTPayload, +) -> &'static str { let shape_circle_cot = circle_payload.to_cot(); let now = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Millis, true); let stale = (chrono::Utc::now() + chrono::Duration::days(1)) @@ -14,21 +17,21 @@ pub fn send_circle_cot(ctx: Context, circle_payload: cot::draws::circle::CircleC } pub fn send_ellipse_cot(ctx: Context) -> &'static str { - let _ = ctx; - "Not implemented: send_ellipse_cot" + let _ = ctx; + "Not implemented: send_ellipse_cot" } pub fn send_rectangle_cot(ctx: Context) -> &'static str { - let _ = ctx; - "Not implemented: send_ellipse_cot" + let _ = ctx; + "Not implemented: send_ellipse_cot" } pub fn send_freedraw_cot(ctx: Context) -> &'static str { - let _ = ctx; - "Not implemented: send_ellipse_cot" + let _ = ctx; + "Not implemented: send_ellipse_cot" } pub fn send_vectordraw_cot(ctx: Context) -> &'static str { - let _ = ctx; - "Not implemented: send_ellipse_cot" -} \ No newline at end of file + let _ = ctx; + "Not implemented: send_ellipse_cot" +} diff --git a/src/tests.rs b/src/tests.rs index 211b825..11ab2a7 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,25 +1,25 @@ #[cfg(test)] mod tests { - use crate::init; - use uuid::Uuid; - use std::vec; + use crate::init; + use std::vec; + use uuid::Uuid; - #[test] - fn uuid_output_is_uuid4_identifier() { - let extension = init().testing(); - let (output, _) = extension.call("uuid", None); + #[test] + fn uuid_output_is_uuid4_identifier() { + let extension = init().testing(); + let (output, _) = extension.call("uuid", None); - let validation = Uuid::parse_str(&output); + let validation = Uuid::parse_str(&output); - assert!(validation.is_ok()) - } + assert!(validation.is_ok()) + } - #[test] - fn uuid_output_throws_if_passed_args() { - let extension = init().testing(); - let args: Vec = vec![1.to_string(),2.to_string()]; - let (output, _) = extension.call("uuid", Some(args)); + #[test] + fn uuid_output_throws_if_passed_args() { + let extension = init().testing(); + let args: Vec = vec![1.to_string(), 2.to_string()]; + let (output, _) = extension.call("uuid", Some(args)); - assert_eq!(output,"") - } + assert_eq!(output, "") + } } diff --git a/src/udp_socket.rs b/src/udp_socket.rs index 20d8833..a135ac2 100644 --- a/src/udp_socket.rs +++ b/src/udp_socket.rs @@ -9,116 +9,119 @@ use std::thread; use crate::cot; pub enum UdpCommand { - SendMessage(String, Context), - Stop, + SendMessage(String, Context), + Stop, } pub struct UdpClient { - pub(crate) tx: Sender, + pub(crate) tx: Sender, } impl UdpClient { - pub fn start(&self, address: String, rx: Receiver, ctx: Context) { - if let Some(ref client) = *UDP_CLIENT.lock().unwrap() { - client.stop(); + pub fn start(&self, address: String, rx: Receiver, ctx: Context) { + if let Some(ref client) = *UDP_CLIENT.lock().unwrap() { + client.stop(); + } + + thread::spawn(move || { + let socket = match UdpSocket::bind("0.0.0.0:0") { + Ok(s) => s, + Err(e) => { + let _ = ctx.callback_data( + "UDP SOCKET ERROR", + "Failed to bind UDP socket", + e.to_string(), + ); + info!("Failed to bind UDP socket: {}", e); + return; + } + }; + + let _ = ctx.callback_data("UDP SOCKET", "EUD Connected", address.clone()); + + let mut running = true; + while running { + match rx.recv() { + Ok(UdpCommand::SendMessage(message, context)) => { + if let Err(e) = socket.send_to(message.as_bytes(), &address) { + info!("Failed to send UDP message: {}", e); + let _ = context.callback_data( + "UDP SOCKET ERROR", + "Failed to send UDP message", + e.to_string(), + ); + } + } + Ok(UdpCommand::Stop) => { + running = false; + info!("Stopping UDP client."); + } + Err(error) => { + info!("Error receiving command: {}", error.to_string()); + } + } + } + }); } - thread::spawn(move || { - let socket = match UdpSocket::bind("0.0.0.0:0") { - Ok(s) => s, - Err(e) => { - let _ = ctx.callback_data( - "UDP SOCKET ERROR", - "Failed to bind UDP socket", - e.to_string(), - ); - info!("Failed to bind UDP socket: {}", e); - return; - } - }; + pub fn send_payload(&self, context: Context, payload: String) { + let tx = self.tx.clone(); + thread::spawn(move || { + tx.send(UdpCommand::SendMessage(payload, context)).unwrap(); + }); + } - let _ = ctx.callback_data("UDP SOCKET", "EUD Connected", address.clone()); - - let mut running = true; - while running { - match rx.recv() { - Ok(UdpCommand::SendMessage(message, context)) => { - if let Err(e) = socket.send_to(message.as_bytes(), &address) { - info!("Failed to send UDP message: {}", e); - let _ = context.callback_data( - "UDP SOCKET ERROR", - "Failed to send UDP message", - e.to_string(), - ); - } - } - Ok(UdpCommand::Stop) => { - running = false; - info!("Stopping UDP client."); - } - Err(error) => { - info!("Error receiving command: {}", error.to_string()); - } - } - } - }); - } - - pub fn send_payload(&self, context: Context, payload: String) { - let tx = self.tx.clone(); - thread::spawn(move || { - tx.send(UdpCommand::SendMessage(payload, context)).unwrap(); - }); - } - - pub fn stop(&self) { - let tx = self.tx.clone(); - thread::spawn(move || { - tx.send(UdpCommand::Stop).unwrap(); - }); - } + pub fn stop(&self) { + let tx = self.tx.clone(); + thread::spawn(move || { + tx.send(UdpCommand::Stop).unwrap(); + }); + } } lazy_static! { - static ref UDP_CLIENT: Arc>> = Arc::new(Mutex::new(None)); + static ref UDP_CLIENT: Arc>> = Arc::new(Mutex::new(None)); } pub fn start(ctx: Context, address: String) -> &'static str { - let (tx, rx): (Sender, Receiver) = mpsc::channel(); + let (tx, rx): (Sender, Receiver) = mpsc::channel(); - let client = UdpClient { tx }; - client.start(address, rx, ctx); + let client = UdpClient { tx }; + client.start(address, rx, ctx); - let mut client_guard = UDP_CLIENT.lock().unwrap(); - *client_guard = Some(client); + let mut client_guard = UDP_CLIENT.lock().unwrap(); + *client_guard = Some(client); - "Starting UDP Client" + "Starting UDP Client" } pub fn send_payload(ctx: Context, payload: String) -> &'static str { - if let Some(ref client) = *UDP_CLIENT.lock().unwrap() { - client.send_payload(ctx, payload); - } else { - let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running"); - } + if let Some(ref client) = *UDP_CLIENT.lock().unwrap() { + client.send_payload(ctx, payload); + } else { + let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running"); + } - "Sending payload to UDP server" + "Sending payload to UDP server" } -pub fn send_gps_cot(ctx: Context, cursor_over_time: cot::gps::ExternalPositionPayload) -> &'static str { - let payload = cursor_over_time.to_cot().convert_to_xml(); - send_payload(ctx, payload); +pub fn send_gps_cot( + ctx: Context, + cursor_over_time: cot::gps::ExternalPositionPayload, +) -> &'static str { + let payload = cursor_over_time.to_cot().convert_to_xml(); + send_payload(ctx, payload); - "Sending GPS Cursor Over Time to UDP server" + "Sending GPS Cursor Over Time to UDP server" } pub fn stop(ctx: Context) -> &'static str { - if let Some(ref client) = *UDP_CLIENT.lock().unwrap() { - client.stop(); - let _ = ctx.callback_null("UDP SOCKET", "EUD Disconnected"); - } else { - let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running"); - } + if let Some(ref client) = *UDP_CLIENT.lock().unwrap() { + client.stop(); + let _ = ctx.callback_null("UDP SOCKET", "EUD Disconnected"); + } else { + let _ = ctx.callback_null("UDP SOCKET ERROR", "UDP Socket is not running"); + } - "Stopping UDP Client" + "Stopping UDP Client" } diff --git a/src/utils/address.rs b/src/utils/address.rs index 86e1c25..e146fdb 100644 --- a/src/utils/address.rs +++ b/src/utils/address.rs @@ -1,23 +1,23 @@ use std::net::{IpAddr, UdpSocket}; pub fn get_local_address() -> String { - fn get_local_ip() -> Result { - let socket = UdpSocket::bind("0.0.0.0:0").map_err(|e| e.to_string())?; - socket.connect("8.8.8.8:80").map_err(|e| e.to_string())?; - socket - .local_addr() - .map(|addr| addr.ip()) - .map_err(|e| e.to_string()) - } + fn get_local_ip() -> Result { + let socket = UdpSocket::bind("0.0.0.0:0").map_err(|e| e.to_string())?; + socket.connect("8.8.8.8:80").map_err(|e| e.to_string())?; + socket + .local_addr() + .map(|addr| addr.ip()) + .map_err(|e| e.to_string()) + } - let parsed_data = get_local_ip(); + let parsed_data = get_local_ip(); - match parsed_data { - Ok(ip) => { - return format!("ws://{}:4152", ip.to_string()); - } - Err(_) => { - return "not provided".to_string(); - } - } + match parsed_data { + Ok(ip) => { + return format!("ws://{}:4152", ip.to_string()); + } + Err(_) => { + return "not provided".to_string(); + } + } } diff --git a/src/utils/log.rs b/src/utils/log.rs index a95194c..981ffb3 100644 --- a/src/utils/log.rs +++ b/src/utils/log.rs @@ -2,11 +2,11 @@ use crate::structs::LogPayload; use log::{error, info, warn}; pub fn log_info(data: LogPayload) -> String { - match data.status.as_str() { - "info" => info!("{}", data.message), - "warn" => warn!("{}", data.message), - "error" => error!("{}", data.message), - _ => error!("{}", "Wrong log call"), - } - "logged".to_string() -} \ No newline at end of file + match data.status.as_str() { + "info" => info!("{}", data.message), + "warn" => warn!("{}", data.message), + "error" => error!("{}", data.message), + _ => error!("{}", "Wrong log call"), + } + "logged".to_string() +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index b378494..32e23c8 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,3 @@ -pub mod uuid; pub mod address; -pub mod log; \ No newline at end of file +pub mod log; +pub mod uuid; diff --git a/src/utils/uuid.rs b/src/utils/uuid.rs index 8f57de8..c6c848a 100644 --- a/src/utils/uuid.rs +++ b/src/utils/uuid.rs @@ -1,7 +1,7 @@ pub fn get_uuid() -> String { - use uuid::Uuid; + use uuid::Uuid; - let id = Uuid::new_v4().to_string(); + let id = Uuid::new_v4().to_string(); - return id; + return id; } diff --git a/src/video_stream.rs b/src/video_stream.rs index 4a38570..ec059e9 100644 --- a/src/video_stream.rs +++ b/src/video_stream.rs @@ -16,7 +16,13 @@ lazy_static! { #[cfg(target_os = "windows")] const CREATE_NO_WINDOW: u32 = 0x08000000; -fn build_rtsp_url(address: &str, port: &str, stream_path: &str, username: &str, password: &str) -> String { +fn build_rtsp_url( + address: &str, + port: &str, + stream_path: &str, + username: &str, + password: &str, +) -> String { if username.is_empty() || password.is_empty() { format!("rtsp://{}:{}/{}", address, port, stream_path) } else { @@ -28,20 +34,22 @@ fn build_rtsp_url(address: &str, port: &str, stream_path: &str, username: &str, } #[cfg(any(target_os = "windows", target_os = "linux"))] -fn spawn_ffmpeg( - rtsp_url: String, - stop_rx: Receiver<()>, - status_tx: Sender>, -) { +fn spawn_ffmpeg(rtsp_url: String, stop_rx: Receiver<()>, status_tx: Sender>) { thread::spawn(move || { let mut cmd = Command::new("ffmpeg"); cmd.args(&[ - "-f","x11grab", - "-framerate","30", - "-video_size","1920x1080", - "-i" ,":0", - "-f","rtsp", - "-rtsp_transport","tcp", + "-f", + "x11grab", + "-framerate", + "30", + "-video_size", + "1920x1080", + "-i", + ":0", + "-f", + "rtsp", + "-rtsp_transport", + "tcp", &rtsp_url, ]);