Skip to content

Commit adc3bce

Browse files
joaoantoniocardosopatrickelectric
authored andcommitted
src: lib: Reformat
1 parent 74d44cc commit adc3bce

35 files changed

Lines changed: 403 additions & 298 deletions

src/lib/controls/onvif/camera.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use onvif::soap;
44
use onvif_schema::transport;
55

6-
use anyhow::{anyhow, Context, Result};
6+
use anyhow::{Context, Result, anyhow};
77
use serde::{Deserialize, Serialize};
88
use tokio::sync::RwLock;
99
use tracing::*;

src/lib/controls/onvif/manager.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
time::Duration,
66
};
77

8-
use anyhow::{anyhow, Context, Result};
8+
use anyhow::{Context, Result, anyhow};
99
use futures::StreamExt as _;
1010
use onvif::soap::client::Credentials;
1111
use serde::Serialize;
@@ -205,7 +205,9 @@ impl Manager {
205205
Ok::<(), onvif::discovery::Error>(()) // Indicate success (discovery part)
206206
}
207207
Err(error) => {
208-
warn!("Task failed: ONVIF discovery failed on interface IP '{ip_addr}': {error:?}");
208+
warn!(
209+
"Task failed: ONVIF discovery failed on interface IP '{ip_addr}': {error:?}"
210+
);
209211
Err(error)
210212
}
211213
}
@@ -222,15 +224,21 @@ impl Manager {
222224
for (iface_name, ip_addr, task_handle) in discovery_tasks {
223225
match task_handle.await {
224226
Ok(Ok(())) => {
225-
trace!("Discovery task for interface '{iface_name}' (IP: {ip_addr}) completed successfully.");
227+
trace!(
228+
"Discovery task for interface '{iface_name}' (IP: {ip_addr}) completed successfully."
229+
);
226230
}
227231
Ok(Err(discovery_error)) => {
228232
// The task ran, but the discovery itself failed
229-
warn!("Discovery task for interface '{iface_name}' (IP: {ip_addr}) reported failure: {discovery_error:?}");
233+
warn!(
234+
"Discovery task for interface '{iface_name}' (IP: {ip_addr}) reported failure: {discovery_error:?}"
235+
);
230236
}
231237
Err(join_error) => {
232238
// The task itself panicked or was cancelled
233-
error!("Discovery task for interface '{iface_name}' (IP: {ip_addr}) panicked or was cancelled: {join_error:?}");
239+
error!(
240+
"Discovery task for interface '{iface_name}' (IP: {ip_addr}) panicked or was cancelled: {join_error:?}"
241+
);
234242
}
235243
}
236244
}
@@ -278,9 +286,7 @@ impl Manager {
278286
let ip_addr = IpAddr::V4(ipv4_network.ip());
279287
trace!(
280288
"Found suitable IPv4 address on interface '{}': {} (Subnet: {})",
281-
interface.name,
282-
ip_addr,
283-
ipv4_network
289+
interface.name, ip_addr, ipv4_network
284290
);
285291
// Return Some tuple, which will be collected and deduplicated by the HashSet
286292
Some((interface.name.clone(), ip_addr))
@@ -448,7 +454,10 @@ impl Manager {
448454
trace!("Device credentials lookup result for UUID={device_uuid:?}: {credentials:?}");
449455

450456
// Iterate through the device's URLs (e.g., different service endpoints)
451-
trace!("Attempting to create OnvifCamera instances for device UUID={device_uuid:?}, IP={device_ip}, found {} URL(s)", device.urls.len());
457+
trace!(
458+
"Attempting to create OnvifCamera instances for device UUID={device_uuid:?}, IP={device_ip}, found {} URL(s)",
459+
device.urls.len()
460+
);
452461
for (index, url) in device.urls.iter().enumerate() {
453462
trace!(
454463
"Processing URL {}/{} for device UUID={device_uuid:?}: {url}",
@@ -486,7 +495,9 @@ impl Manager {
486495
);
487496

488497
let Some(streams_informations) = streams_information_option else {
489-
error!("Failed getting stream information (streams_information is None) for camera created from URL: {url}");
498+
error!(
499+
"Failed getting stream information (streams_information is None) for camera created from URL: {url}"
500+
);
490501
continue; // Move to the next URL
491502
};
492503

src/lib/helper/develop.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use anyhow::{anyhow, Result};
3+
use anyhow::{Result, anyhow};
44
use thirtyfour::prelude::*;
55
use tokio::{process::Command, runtime::Runtime, sync::RwLock};
66
use tracing::*;
@@ -255,8 +255,8 @@ async fn task(session_cycles: i32) -> Result<()> {
255255
// Ignore first cycle
256256
if current_cycle > 0 {
257257
return Err(anyhow!(
258-
"Thread leak detected on cycle {current_cycle}:\n{new_tasks_since_last_cycle:#?}\n{tasks_alive_from_last_cycle:#?}"
259-
));
258+
"Thread leak detected on cycle {current_cycle}:\n{new_tasks_since_last_cycle:#?}\n{tasks_alive_from_last_cycle:#?}"
259+
));
260260
}
261261
};
262262

@@ -274,8 +274,12 @@ async fn task(session_cycles: i32) -> Result<()> {
274274
info!("Tasks alive since last cycle: {number_of_tasks_alive_from_last_cycle}");
275275

276276
if number_of_new_tasks_since_last_cycle > 0 || number_of_tasks_alive_from_last_cycle > 0 {
277-
info!("The following tasks were created since last cycle:\n{new_tasks_since_last_cycle:#?}");
278-
info!("The following tasks were alive since last cycle:\n{tasks_alive_from_last_cycle:#?}")
277+
info!(
278+
"The following tasks were created since last cycle:\n{new_tasks_since_last_cycle:#?}"
279+
);
280+
info!(
281+
"The following tasks were alive since last cycle:\n{tasks_alive_from_last_cycle:#?}"
282+
)
279283
}
280284
}
281285

src/lib/helper/threads.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ pub fn process_tasks() -> HashMap<u32, String> {
4343
}
4444

4545
pub fn start_thread_counter_thread() {
46-
thread::spawn(move || loop {
47-
info!("Number of child processes: {}", process_task_counter());
48-
thread::sleep(Duration::from_secs(1));
46+
thread::spawn(move || {
47+
loop {
48+
info!("Number of child processes: {}", process_task_counter());
49+
thread::sleep(Duration::from_secs(1));
50+
}
4951
});
5052
}
5153

src/lib/logger/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use tokio::sync::broadcast::{Receiver, Sender};
88
use tracing::{metadata::LevelFilter, *};
99
use tracing_log::LogTracer;
1010
use tracing_subscriber::{
11+
EnvFilter, Layer,
1112
fmt::{self, MakeWriter},
1213
layer::SubscriberExt,
13-
EnvFilter, Layer,
1414
};
1515

1616
use crate::cli;

src/lib/mavlink/manager.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
sync::{Arc, Mutex, RwLock},
44
};
55

6-
use mavlink::{common::MavMessage, MavConnection, MavHeader};
6+
use mavlink::{MavConnection, MavHeader, common::MavMessage};
77

88
use anyhow::{Context, Result};
99
use tokio::sync::broadcast;
@@ -155,7 +155,9 @@ impl Manager {
155155
);
156156
}
157157
Err(broadcast::error::RecvError::Lagged(samples)) => {
158-
warn!("Channel is lagged behind by {samples} messages. Expect degraded performance on the mavlink responsiviness.");
158+
warn!(
159+
"Channel is lagged behind by {samples} messages. Expect degraded performance on the mavlink responsiviness."
160+
);
159161
continue;
160162
}
161163
};

src/lib/mavlink/mavlink_camera.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

3-
use anyhow::{anyhow, Context, Result};
4-
use mavlink::{common::MavMessage, MavHeader};
3+
use anyhow::{Context, Result, anyhow};
4+
use mavlink::{MavHeader, common::MavMessage};
55
use tokio::sync::broadcast;
66
use tracing::*;
77
use url::Url;
@@ -187,7 +187,9 @@ impl MavlinkCameraInner {
187187
}
188188
Ok(Message::ToBeSent(_)) => (),
189189
Err(error) => {
190-
error!("Failed receiving from broadcast channel: {error:#?}. Resubscribing to the channel...");
190+
error!(
191+
"Failed receiving from broadcast channel: {error:#?}. Resubscribing to the channel..."
192+
);
191193

192194
receiver = receiver.resubscribe();
193195
}
@@ -444,7 +446,10 @@ impl MavlinkCameraInner {
444446
let result = match crate::video::video_source::reset_controls(source_string).await {
445447
Ok(_) => mavlink::common::MavResult::MAV_RESULT_ACCEPTED,
446448
Err(error) => {
447-
error!("Failed to reset {source_string:?} controls with its default values as {:#?}:{:#?}. Reason: {error:?}", camera.component.system_id, camera.component.component_id);
449+
error!(
450+
"Failed to reset {source_string:?} controls with its default values as {:#?}:{:#?}. Reason: {error:?}",
451+
camera.component.system_id, camera.component.component_id
452+
);
448453
mavlink::common::MavResult::MAV_RESULT_DENIED
449454
}
450455
};
@@ -514,7 +519,10 @@ impl MavlinkCameraInner {
514519
}
515520
VIDEO_STREAM_INFORMATION_ID => {
516521
if !validate_stream_id(camera, data.param2) {
517-
warn!("MAV_CMD_REQUEST_MESSAGE(VIDEO_STREAM_INFORMATION): unknown stream id: {:#?}.", data.param2);
522+
warn!(
523+
"MAV_CMD_REQUEST_MESSAGE(VIDEO_STREAM_INFORMATION): unknown stream id: {:#?}.",
524+
data.param2
525+
);
518526
send_ack(
519527
camera,
520528
&sender,
@@ -622,7 +630,10 @@ impl MavlinkCameraInner {
622630
{
623631
Ok(_) => mavlink::common::ParamAck::PARAM_ACK_ACCEPTED,
624632
Err(error) => {
625-
error!("Failed to set parameter {control_id:?} with value {control_value:?} for {:#?}. Reason: {error:?}", camera.component.component_id);
633+
error!(
634+
"Failed to set parameter {control_id:?} with value {control_value:?} for {:#?}. Reason: {error:?}",
635+
camera.component.component_id
636+
);
626637
mavlink::common::ParamAck::PARAM_ACK_FAILED
627638
}
628639
};

src/lib/server/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use actix_web::{http::StatusCode, ResponseError};
1+
use actix_web::{ResponseError, http::StatusCode};
22

33
use paperclip::actix::api_v2_errors;
44
use validator::ValidationErrors;

src/lib/server/manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use actix_cors::Cors;
22
use actix_extensible_rate_limit::{
3-
backend::{memory::InMemoryBackend, SimpleInputFunctionBuilder},
43
RateLimiter,
4+
backend::{SimpleInputFunctionBuilder, memory::InMemoryBackend},
55
};
6-
use actix_web::{error::JsonPayloadError, App, HttpRequest, HttpServer};
6+
use actix_web::{App, HttpRequest, HttpServer, error::JsonPayloadError};
77
use paperclip::{
8-
actix::{web, OpenApiExt},
8+
actix::{OpenApiExt, web},
99
v2::models::{Api, Info},
1010
};
1111
use tracing::*;

src/lib/server/pages.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use actix_web::{
2+
HttpRequest, HttpResponse,
23
http::header,
34
rt,
45
web::{self, Json},
5-
HttpRequest, HttpResponse,
66
};
77
use actix_ws::Message;
88
use futures::StreamExt;
9-
use paperclip::actix::{api_v2_operation, Apiv2Schema, CreatedJson};
9+
use paperclip::actix::{Apiv2Schema, CreatedJson, api_v2_operation};
1010
use serde::{Deserialize, Serialize};
1111
use serde_json::json;
1212
use tokio::time::Duration;
@@ -149,7 +149,7 @@ pub struct UnauthenticateOnvifDeviceRequest {
149149

150150
use std::{ffi::OsStr, path::Path};
151151

152-
use include_dir::{include_dir, Dir};
152+
use include_dir::{Dir, include_dir};
153153

154154
static DIST: Dir<'_> = include_dir!("frontend/dist");
155155

0 commit comments

Comments
 (0)