diff --git a/src/bin/main.rs b/src/bin/main.rs index fa3cbe06..18a181f7 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,13 +1,16 @@ -#![warn(rust_2018_idioms)] +#![deny(rust_2018_idioms)] #![deny(clippy::todo)] #![deny(clippy::unimplemented)] #![deny(clippy::missing_safety_doc)] -#[allow(unused_imports)] // TODO: Deny unused imports. // Primarily used for debug purposes. -#[cfg(feature = "log")] -#[macro_use] -extern crate log; +cfg_if::cfg_if! { + if #[cfg(feature = "log")] { + #[allow(unused_imports)] + #[macro_use] + extern crate log; + } +} use std::{ boxed::Box, diff --git a/src/lib.rs b/src/lib.rs index c6eaa9f1..1713c0f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,15 +5,19 @@ //! than the actual usage of the application. If you are instead looking for documentation regarding the *usage* of //! bottom, refer to [here](https://clementtsang.github.io/bottom/stable/). -#![warn(rust_2018_idioms)] +#![deny(rust_2018_idioms)] #![deny(clippy::todo)] #![deny(clippy::unimplemented)] #![deny(clippy::missing_safety_doc)] -#[allow(unused_imports)] // TODO: Deny unused imports. -// Only used for builds not intended for release. -#[cfg(feature = "log")] -#[macro_use] -extern crate log; + +// Primarily used for debug purposes. +cfg_if::cfg_if! { + if #[cfg(feature = "log")] { + #[allow(unused_imports)] + #[macro_use] + extern crate log; + } +} use std::{ boxed::Box, @@ -71,6 +75,7 @@ pub type Pid = usize; #[cfg(target_family = "unix")] pub type Pid = libc::pid_t; +/// Events sent to the main thread. #[derive(Debug)] pub enum BottomEvent { Resize, @@ -82,6 +87,7 @@ pub enum BottomEvent { Terminate, } +/// Events sent to the collection thread. #[derive(Debug)] pub enum ThreadEvent { Reset, @@ -241,19 +247,17 @@ pub fn read_config(config_location: Option<&String>) -> error::Result) -> error::Result { if let Some(path) = config_path { if let Ok(config_string) = fs::read_to_string(path) { - // We found a config file! Ok(toml_edit::de::from_str(config_string.as_str())?) } else { - // Config file DNE... if let Some(parent_path) = path.parent() { fs::create_dir_all(parent_path)?; } - // fs::File::create(path)?.write_all(CONFIG_TOP_HEAD.as_bytes())?; + fs::File::create(path)?.write_all(CONFIG_TEXT.as_bytes())?; Ok(Config::default()) } } else { - // Don't write, the config path was somehow None... + // Don't write... Ok(Config::default()) } } @@ -264,10 +268,10 @@ pub fn try_drawing( ) -> error::Result<()> { if let Err(err) = painter.draw_data(terminal, app) { cleanup_terminal(terminal)?; - return Err(err); + Err(err) + } else { + Ok(()) } - - Ok(()) } pub fn cleanup_terminal( @@ -323,7 +327,7 @@ pub fn panic_hook(panic_info: &PanicInfo<'_>) { ) .unwrap(); - // Print stack trace. Must be done after! + // Print stack trace. Must be done after! execute!( stdout, Print(format!(