aboutsummaryrefslogtreecommitdiff
path: root/crates/whirl_api
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-28 00:06:40 +0000
committerFuwn <[email protected]>2021-05-28 00:06:40 +0000
commitd87b4825480f938cfa552421e220d8f85a1bee10 (patch)
treed9c69c0dc4f5a9e876460d10e101d936f424bee5 /crates/whirl_api
parentMerge branch 'develop' of https://github.com/Whirlsplash/whirl into develop (diff)
downloadwhirl-d87b4825480f938cfa552421e220d8f85a1bee10.tar.xz
whirl-d87b4825480f938cfa552421e220d8f85a1bee10.zip
fix(global): a lot of clippy warnings
This change makes clippy **a lot** more strict.
Diffstat (limited to 'crates/whirl_api')
-rw-r--r--crates/whirl_api/Cargo.toml1
-rw-r--r--crates/whirl_api/src/lib.rs29
-rw-r--r--crates/whirl_api/src/routes/stats/mod.rs9
3 files changed, 32 insertions, 7 deletions
diff --git a/crates/whirl_api/Cargo.toml b/crates/whirl_api/Cargo.toml
index a0ffe33..de658f5 100644
--- a/crates/whirl_api/Cargo.toml
+++ b/crates/whirl_api/Cargo.toml
@@ -22,6 +22,7 @@ actix-cors = "0.5.4"
sysinfo = "0.18.0"
whirl_common = { path = "../whirl_common" }
tokio = { version = "1.6.0", features = ["full"] }
+num-traits = "0.2.14"
# Serialization
serde = "1.0.126"
diff --git a/crates/whirl_api/src/lib.rs b/crates/whirl_api/src/lib.rs
index d2f7811..e6660a7 100644
--- a/crates/whirl_api/src/lib.rs
+++ b/crates/whirl_api/src/lib.rs
@@ -10,7 +10,15 @@
decl_macro,
proc_macro_hygiene
)]
-#![warn(rust_2018_idioms)]
+#![deny(
+ warnings,
+ nonstandard_style,
+ unused,
+ future_incompatible,
+ rust_2018_idioms,
+ unsafe_code
+)]
+#![deny(clippy::all, clippy::nursery, clippy::pedantic)]
#![recursion_limit = "128"]
#[macro_use]
@@ -25,6 +33,14 @@ mod routes;
pub struct Api;
impl Api {
/// Begin handling connections on the web-server.
+ ///
+ /// # Errors
+ /// - An error may arise if the web-server is unable to bind the specified
+ /// port.
+ ///
+ /// # Panics
+ /// - A panic may occur if the mpsc sender is unable to send a clone of the
+ /// server.
pub async fn listen(
tx: std::sync::mpsc::Sender<actix_web::dev::Server>,
address: &str,
@@ -42,23 +58,28 @@ impl Api {
info!("http api now listening at {}", address);
- let _ = tx.send(server.clone());
+ tx.send(server.clone()).unwrap();
sys.block_on(server)
}
}
+/// # Panics
+/// - A panic may occur if the mpsc sender is unable to send a clone of the
+/// server.
+#[must_use]
pub fn make() -> tokio::task::JoinHandle<()> {
// actix_web::rt::System::new("").block_on(rx.recv().unwrap().stop(true));
tokio::spawn(async move {
- let _ = crate::Api::listen(
+ crate::Api::listen(
std::sync::mpsc::channel().0,
&*format!(
"0.0.0.0:{}",
whirl_config::Config::get().whirlsplash.api.port
),
)
- .await;
+ .await
+ .unwrap();
})
}
diff --git a/crates/whirl_api/src/routes/stats/mod.rs b/crates/whirl_api/src/routes/stats/mod.rs
index 5a41630..02c3d22 100644
--- a/crates/whirl_api/src/routes/stats/mod.rs
+++ b/crates/whirl_api/src/routes/stats/mod.rs
@@ -3,7 +3,10 @@
pub mod structures;
+use std::convert::TryFrom;
+
use actix_web::HttpResponse;
+use num_traits::cast::AsPrimitive;
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
use crate::routes::stats::structures::{Statistics, StatisticsProcess, StatisticsSystem};
@@ -20,14 +23,14 @@ pub fn statistics() -> HttpResponse {
system: StatisticsSystem {
os_type: sys.get_name().unwrap(),
release: sys.get_kernel_version().unwrap(),
- uptime: whirl_common::system::seconds_to_hrtime(
- sysinfo::System::new().get_uptime() as usize
+ uptime: whirl_common::system::seconds_to_hrtime(
+ usize::try_from(sysinfo::System::new().get_uptime()).unwrap(),
),
},
process: StatisticsProcess {
// (process.cpu_usage() * 100.0).round() / 100.0
memory_usage: (process.memory() / 1000).to_string(),
- cpu_usage: (process.cpu_usage() / sys.get_processors().len() as f32).to_string(),
+ cpu_usage: (process.cpu_usage() / sys.get_processors().len().as_(): f32).to_string(),
// uptime: seconds_to_hrtime((sys.get_uptime() - process.start_time()) as usize),
},
})