generated from PlexSheep/baserepo
make clippy happier
cargo devel CI / cargo CI (push) Failing after 1m8s
Details
cargo devel CI / cargo CI (push) Failing after 1m8s
Details
This commit is contained in:
parent
af2974d843
commit
faa4023f95
|
@ -34,17 +34,17 @@ where
|
||||||
T: std::fmt::Debug,
|
T: std::fmt::Debug,
|
||||||
{
|
{
|
||||||
if total < T::from(KIBI).unwrap() {
|
if total < T::from(KIBI).unwrap() {
|
||||||
return format!("{total} B");
|
format!("{total} B")
|
||||||
} else if T::from(KIBI).unwrap() <= total && total < T::from(MEBI).unwrap() {
|
} else if T::from(KIBI).unwrap() <= total && total < T::from(MEBI).unwrap() {
|
||||||
return format!("{:.2} K", total.to_f64().unwrap() / KIBI as f64);
|
format!("{:.2} K", total.to_f64().unwrap() / KIBI as f64)
|
||||||
} else if T::from(MEBI).unwrap() <= total && total < T::from(GIBI).unwrap() {
|
} else if T::from(MEBI).unwrap() <= total && total < T::from(GIBI).unwrap() {
|
||||||
return format!("{:.2} M", total.to_f64().unwrap() / MEBI as f64);
|
format!("{:.2} M", total.to_f64().unwrap() / MEBI as f64)
|
||||||
} else if T::from(GIBI).unwrap() <= total && total < T::from(TEBI).unwrap() {
|
} else if T::from(GIBI).unwrap() <= total && total < T::from(TEBI).unwrap() {
|
||||||
return format!("{:.2} G", total.to_f64().unwrap() / GIBI as f64);
|
format!("{:.2} G", total.to_f64().unwrap() / GIBI as f64)
|
||||||
} else if T::from(TEBI).unwrap() <= total && total < T::from(PEBI).unwrap() {
|
} else if T::from(TEBI).unwrap() <= total && total < T::from(PEBI).unwrap() {
|
||||||
return format!("{:.2} T", total.to_f64().unwrap() / TEBI as f64);
|
format!("{:.2} T", total.to_f64().unwrap() / TEBI as f64)
|
||||||
} else if T::from(PEBI).unwrap() <= total && total < T::from(EXBI).unwrap() {
|
} else if T::from(PEBI).unwrap() <= total && total < T::from(EXBI).unwrap() {
|
||||||
return format!("{:.2} P", total.to_f64().unwrap() / PEBI as f64);
|
format!("{:.2} P", total.to_f64().unwrap() / PEBI as f64)
|
||||||
}
|
}
|
||||||
// now we are starting to reach the sizes that are pretty unrealistic
|
// now we are starting to reach the sizes that are pretty unrealistic
|
||||||
// (as of 2023 that is, hello future)
|
// (as of 2023 that is, hello future)
|
||||||
|
@ -53,9 +53,9 @@ where
|
||||||
// to work with a fixed, larger sized datatype
|
// to work with a fixed, larger sized datatype
|
||||||
else {
|
else {
|
||||||
let total: u128 = total.to_u128().unwrap();
|
let total: u128 = total.to_u128().unwrap();
|
||||||
if EXBI <= total && total < ZEBI {
|
if (EXBI..ZEBI).contains(&total) {
|
||||||
return format!("{:.2} E", total.to_f64().unwrap() / EXBI as f64);
|
return format!("{:.2} E", total.to_f64().unwrap() / EXBI as f64);
|
||||||
} else if ZEBI <= total && total < YOBI {
|
} else if (ZEBI..YOBI).contains(&total) {
|
||||||
return format!("{:.2} Z", total.to_f64().unwrap() / ZEBI as f64);
|
return format!("{:.2} Z", total.to_f64().unwrap() / ZEBI as f64);
|
||||||
} else if YOBI <= total {
|
} else if YOBI <= total {
|
||||||
return format!("{:.2} Y", total.to_f64().unwrap() / YOBI as f64);
|
return format!("{:.2} Y", total.to_f64().unwrap() / YOBI as f64);
|
||||||
|
|
|
@ -2,6 +2,6 @@ use libpt_bintols::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mkdmp() {
|
fn mkdmp() {
|
||||||
let v = vec![true, true, false];
|
let v = [true, true, false];
|
||||||
investigate_memory_layout!(bool, v);
|
investigate_memory_layout!(bool, v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
ops::Deref,
|
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::atomic::{AtomicBool, Ordering},
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
};
|
};
|
||||||
|
@ -25,17 +24,8 @@ pub mod error;
|
||||||
use error::*;
|
use error::*;
|
||||||
|
|
||||||
pub use tracing::{debug, error, info, trace, warn, Level};
|
pub use tracing::{debug, error, info, trace, warn, Level};
|
||||||
use tracing_appender::{
|
use tracing_appender::{self, non_blocking::NonBlocking};
|
||||||
self,
|
use tracing_subscriber::fmt::{format::FmtSpan, time};
|
||||||
non_blocking::{NonBlocking, WorkerGuard},
|
|
||||||
};
|
|
||||||
use tracing_subscriber::{
|
|
||||||
fmt::{
|
|
||||||
format::FmtSpan,
|
|
||||||
time::{self, FormatTime},
|
|
||||||
},
|
|
||||||
prelude::*,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
/// The log level used when none is specified
|
/// The log level used when none is specified
|
||||||
|
@ -43,7 +33,7 @@ pub const DEFAULT_LOG_LEVEL: Level = Level::INFO;
|
||||||
/// The path where logs are stored when no path is given.
|
/// The path where logs are stored when no path is given.
|
||||||
///
|
///
|
||||||
/// Currently, this is `/dev/null`, meaning they will be written to the void = discarded.
|
/// Currently, this is `/dev/null`, meaning they will be written to the void = discarded.
|
||||||
pub const DEFAULT_LOG_DIR: &'static str = "/dev/null";
|
pub const DEFAULT_LOG_DIR: &str = "/dev/null";
|
||||||
|
|
||||||
static INITIALIZED: AtomicBool = AtomicBool::new(false);
|
static INITIALIZED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
@ -59,8 +49,7 @@ impl Logger {
|
||||||
///
|
///
|
||||||
/// Creates a new uninitialized [`Logger`] object.
|
/// Creates a new uninitialized [`Logger`] object.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let l = Logger {};
|
Logger {}
|
||||||
l
|
|
||||||
}
|
}
|
||||||
/// ## initializes the logger
|
/// ## initializes the logger
|
||||||
///
|
///
|
||||||
|
@ -132,7 +121,7 @@ impl Logger {
|
||||||
// only init if no init has been performed yet
|
// only init if no init has been performed yet
|
||||||
if INITIALIZED.load(Ordering::Relaxed) {
|
if INITIALIZED.load(Ordering::Relaxed) {
|
||||||
warn!("trying to reinitialize the logger, ignoring");
|
warn!("trying to reinitialize the logger, ignoring");
|
||||||
bail!(Error::Usage(format!("logging is already initialized")));
|
bail!(Error::Usage("logging is already initialized".to_string()));
|
||||||
}
|
}
|
||||||
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
|
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
|
||||||
.with_level(display_level)
|
.with_level(display_level)
|
||||||
|
@ -256,6 +245,12 @@ impl Logger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Logger {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Logger {
|
impl fmt::Debug for Logger {
|
||||||
/// ## DEBUG representation for [`Logger`]
|
/// ## DEBUG representation for [`Logger`]
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
@ -269,5 +264,5 @@ impl fmt::Debug for Logger {
|
||||||
|
|
||||||
fn new_file_appender(log_dir: PathBuf) -> NonBlocking {
|
fn new_file_appender(log_dir: PathBuf) -> NonBlocking {
|
||||||
let file_appender = tracing_appender::rolling::daily(log_dir.clone(), "log");
|
let file_appender = tracing_appender::rolling::daily(log_dir.clone(), "log");
|
||||||
return tracing_appender::non_blocking(file_appender).0;
|
tracing_appender::non_blocking(file_appender).0
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
//! The networking module contains various tools related to connections. For example, it contains a
|
//! The networking module contains various tools related to connections. For example, it contains a
|
||||||
//! tool that has the purpose to check if your connection is consistently available.
|
//! tool that has the purpose to check if your connection is consistently available.
|
||||||
|
|
||||||
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||||
// we want docs
|
// we want docs
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![warn(rustdoc::missing_crate_level_docs)]
|
#![warn(rustdoc::missing_crate_level_docs)]
|
||||||
|
@ -17,24 +17,24 @@
|
||||||
// enable clippy's extra lints, the pedantic version
|
// enable clippy's extra lints, the pedantic version
|
||||||
#![warn(clippy::pedantic)]
|
#![warn(clippy::pedantic)]
|
||||||
|
|
||||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// monitor your connection
|
/// monitor your connection
|
||||||
pub mod monitoring;
|
pub mod monitoring;
|
||||||
|
|
||||||
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// how long to wait for a remove server to respond in ms
|
/// how long to wait for a remove server to respond in ms
|
||||||
pub const DEFAULT_REQUEST_TIMEOUT: u64 = 2000;
|
pub const DEFAULT_REQUEST_TIMEOUT: u64 = 2000;
|
||||||
|
|
||||||
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
|
// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! This module offers functions to monitor your network.
|
//! This module offers functions to monitor your network.
|
||||||
|
|
||||||
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
|
||||||
// we want docs
|
// we want docs
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![warn(rustdoc::missing_crate_level_docs)]
|
#![warn(rustdoc::missing_crate_level_docs)]
|
||||||
|
@ -13,21 +13,21 @@
|
||||||
// enable clippy's extra lints, the pedantic version
|
// enable clippy's extra lints, the pedantic version
|
||||||
#![warn(clippy::pedantic)]
|
#![warn(clippy::pedantic)]
|
||||||
|
|
||||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
pub mod uptime;
|
pub mod uptime;
|
||||||
|
|
||||||
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
|
// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
use std::{fmt, time::Duration};
|
use std::{fmt, time::Duration};
|
||||||
|
|
||||||
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
use libpt_log::*;
|
use libpt_log::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
use reqwest;
|
use reqwest;
|
||||||
|
|
||||||
|
@ -31,25 +31,24 @@ use serde_json;
|
||||||
|
|
||||||
use libpt_core::divider;
|
use libpt_core::divider;
|
||||||
|
|
||||||
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
// TYPES /////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// urls used for checking by default
|
/// urls used for checking by default
|
||||||
pub const DEFAULT_CHECK_URLS: &'static [&'static str] =
|
pub const DEFAULT_CHECK_URLS: &[&str] = &["https://www.cscherr.de", "https://www.cloudflare.com"];
|
||||||
&["https://www.cscherr.de", "https://www.cloudflare.com"];
|
|
||||||
|
|
||||||
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
// STATICS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
// MACROS ////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// ## Describes an uptime status
|
/// ## Describes an uptime status
|
||||||
///
|
///
|
||||||
/// [`UptimeStatus`] describes the result of an uptime check.
|
/// [`UptimeStatus`] describes the result of an uptime check.
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct UptimeStatus {
|
pub struct Status {
|
||||||
/// true if the [`UptimeStatus`] is considered successful
|
/// true if the [`UptimeStatus`] is considered successful
|
||||||
pub success: bool,
|
pub success: bool,
|
||||||
/// the percentage of reachable urls out of the total urls
|
/// the percentage of reachable urls out of the total urls
|
||||||
|
@ -65,13 +64,13 @@ pub struct UptimeStatus {
|
||||||
pub timeout: u64,
|
pub timeout: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Main implementation
|
/// Main implementation
|
||||||
impl UptimeStatus {
|
impl Status {
|
||||||
/// ## create a new `UptimeStatus` and perform it's check
|
/// ## create a new `UptimeStatus` and perform it's check
|
||||||
pub fn new(success_ratio_target: u8, urls: Vec<String>, timeout: u64) -> Self {
|
pub fn new(success_ratio_target: u8, urls: Vec<String>, timeout: u64) -> Self {
|
||||||
assert!(success_ratio_target <= 100);
|
assert!(success_ratio_target <= 100);
|
||||||
let mut status = UptimeStatus {
|
let mut status = Status {
|
||||||
success: false,
|
success: false,
|
||||||
success_ratio: 0,
|
success_ratio: 0,
|
||||||
success_ratio_target,
|
success_ratio_target,
|
||||||
|
@ -139,7 +138,7 @@ impl UptimeStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
impl fmt::Debug for UptimeStatus {
|
impl fmt::Debug for Status {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut urls: Vec<&str> = Vec::new();
|
let mut urls: Vec<&str> = Vec::new();
|
||||||
for url in &self.urls {
|
for url in &self.urls {
|
||||||
|
@ -150,7 +149,7 @@ impl fmt::Debug for UptimeStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
impl fmt::Display for UptimeStatus {
|
impl fmt::Display for Status {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut urls: Vec<&str> = Vec::new();
|
let mut urls: Vec<&str> = Vec::new();
|
||||||
for url in &self.urls {
|
for url in &self.urls {
|
||||||
|
@ -182,7 +181,7 @@ pub fn continuous_uptime_monitor(
|
||||||
let interval = std::time::Duration::from_millis(interval);
|
let interval = std::time::Duration::from_millis(interval);
|
||||||
let mut last_downtime: Option<SystemTime> = None;
|
let mut last_downtime: Option<SystemTime> = None;
|
||||||
let mut last_uptime: Option<SystemTime> = None;
|
let mut last_uptime: Option<SystemTime> = None;
|
||||||
let mut status = UptimeStatus::new(success_ratio_target, urls, timeout);
|
let mut status = Status::new(success_ratio_target, urls, timeout);
|
||||||
// we assume that the last status was up, so the binary shows the first status if its a
|
// we assume that the last status was up, so the binary shows the first status if its a
|
||||||
// failure.
|
// failure.
|
||||||
let mut last_was_up: bool = true;
|
let mut last_was_up: bool = true;
|
||||||
|
@ -224,13 +223,13 @@ pub fn continuous_uptime_monitor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
|
||||||
/// Displays the current status for the [continuous uptime monitor](continuous_uptime_monitor)
|
/// Displays the current status for the [continuous uptime monitor](continuous_uptime_monitor)
|
||||||
fn display_uptime_status(
|
fn display_uptime_status(
|
||||||
msg: &str,
|
msg: &str,
|
||||||
last_uptime: Option<SystemTime>,
|
last_uptime: Option<SystemTime>,
|
||||||
last_downtime: Option<SystemTime>,
|
last_downtime: Option<SystemTime>,
|
||||||
status: &UptimeStatus,
|
status: &Status,
|
||||||
) {
|
) {
|
||||||
// I know it's weird that this has two spaces too much, but somehow just the tabs is missing
|
// I know it's weird that this has two spaces too much, but somehow just the tabs is missing
|
||||||
// two spaces.
|
// two spaces.
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
#[cfg(feature = "bintols")]
|
#[cfg(feature = "bintols")]
|
||||||
pub use libpt_bintols as bintols;
|
pub use libpt_bintols as bintols;
|
||||||
#[cfg(feature = "ccc")]
|
|
||||||
pub use libpt_ccc as ccc;
|
|
||||||
#[cfg(feature = "core")]
|
#[cfg(feature = "core")]
|
||||||
pub use libpt_core as core;
|
pub use libpt_core as core;
|
||||||
#[cfg(feature = "log")]
|
#[cfg(feature = "log")]
|
||||||
|
|
Reference in New Issue