diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-06-08 02:28:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 02:28:36 -0400 |
commit | f0121e6af4c57851411475dff705864dfacf6d5c (patch) | |
tree | d5765c1990a3c7a4a09d9b7d66de836fe12fa6e2 | |
parent | 086b622c6665cdbb9d8d9a5447543abae67d9783 (diff) |
other: enforce unused_imports lint again (#1189)
* other: enforce unused_imports lint again
I think there shouldn't be any issues with enforcing this now...
* set up cfg block so the logging feature doesn't break clippy
* some cleanup + comments
-rw-r--r-- | src/bin/main.rs | 13 | ||||
-rw-r--r-- | src/lib.rs | 32 |
2 files changed, 26 insertions, 19 deletions
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, @@ -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<Option<Pat pub fn create_or_get_config(config_path: &Option<PathBuf>) -> error::Result<Config> { 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!( |