From 4ca561ccd8ae9809612b0fc3ee6e154fee35d677 Mon Sep 17 00:00:00 2001 From: Skye Jensen Date: Mon, 10 Aug 2020 20:56:21 -0400 Subject: [PATCH] Trim dependencies and rewrite prettify_kib --- Cargo.lock | 91 +++------------------------------------------ Cargo.toml | 6 +-- shell.nix | 2 +- src/tiles/memory.rs | 34 +++++------------ 4 files changed, 19 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93aa3a9..1a0efb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,12 +9,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "arc-swap" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" - [[package]] name = "async-trait" version = "0.1.36" @@ -110,12 +104,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -352,35 +340,12 @@ dependencies = [ "kernel32-sys", "libc", "log", - "miow 0.2.1", + "miow", "net2", "slab", "winapi 0.2.8", ] -[[package]] -name = "mio-named-pipes" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" -dependencies = [ - "log", - "mio", - "miow 0.3.5", - "winapi 0.3.9", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio", -] - [[package]] name = "miow" version = "0.2.1" @@ -393,16 +358,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "miow" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" -dependencies = [ - "socket2", - "winapi 0.3.9", -] - [[package]] name = "net2" version = "0.2.34" @@ -588,12 +543,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "rustybar" version = "0.1.0" @@ -604,7 +553,6 @@ dependencies = [ "dbus-tokio", "futures", "futures-async-stream", - "futures-util", "serde", "serde_json", "smart-default", @@ -622,18 +570,18 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "serde" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ "proc-macro2", "quote", @@ -651,16 +599,6 @@ dependencies = [ "serde", ] -[[package]] -name = "signal-hook-registry" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" -dependencies = [ - "arc-swap", - "libc", -] - [[package]] name = "slab" version = "0.4.2" @@ -678,18 +616,6 @@ dependencies = [ "syn", ] -[[package]] -name = "socket2" -version = "0.3.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "winapi 0.3.9", -] - [[package]] name = "strsim" version = "0.8.0" @@ -757,21 +683,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" dependencies = [ "bytes", - "fnv", "futures-core", - "iovec", "lazy_static", - "libc", "memchr", "mio", - "mio-named-pipes", - "mio-uds", "num_cpus", "pin-project-lite", - "signal-hook-registry", "slab", "tokio-macros", - "winapi 0.3.9", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 570ae02..9fd44c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustybar" version = "0.1.0" -authors = ["Artemis Tosini "] +authors = ["Artemis Tosini ", "Skye Jensen "] edition = "2018" [features] @@ -14,12 +14,12 @@ dbus = "0.8" dbus-tokio = "0.5" futures = "0.3" futures-async-stream = "0.2" -futures-util = "0.3" +#futures-util = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" smart-default = "0.6" structopt = "0.3" -tokio = { version = "0.2", features = ["full"] } +tokio = { version = "0.2", features = ["fs", "io-std", "time"] } toml = "0.5" uuid = { version = "0.8", features = [ "v4" ] } diff --git a/shell.nix b/shell.nix index 3d96aba..6a39c58 100644 --- a/shell.nix +++ b/shell.nix @@ -3,6 +3,6 @@ with pkgs; stdenv.mkDerivation { name = "rustybar-env"; nativeBuildInputs = [ pkgconfig ]; - buildInputs = [ dbus ]; + buildInputs = [ dbus rustup ]; } diff --git a/src/tiles/memory.rs b/src/tiles/memory.rs index 992c6c9..c235212 100644 --- a/src/tiles/memory.rs +++ b/src/tiles/memory.rs @@ -6,30 +6,16 @@ use tokio::fs::File; use tokio::prelude::*; fn prettify_kib(kib: u64) -> Box { - if kib > u64::MAX / 1024 { - panic!("Too much memory"); - } - let mut mem = kib; - let mut stages = 0u8; - while mem >= 1024 { - stages += 1; - mem /= 1024; - } - format!( - "{} {}iB", - mem, - match stages { - 0 => 'k', - 1 => 'M', - 2 => 'G', - 3 => 'T', - 4 => 'P', - 5 => 'E', - 6 => 'Z', - _ => panic!("Too much memory, for real this time"), - } - ) - .into_boxed_str() + let (mem, unit) = match kib { + 0..=0x3ff => (kib, 'k'), + 0x400..=0xfffff => (kib >> 10, 'M'), + 0x100000..=0x3fffffff => (kib >> 20, 'G'), + 0x40000000..=0xffffffffff => (kib >> 30, 'T'), + 0x10000000000..=0x3ffffffffffff => (kib >> 40, 'P'), + 0x4000000000000..=0xfffffffffffffff => (kib >> 50, 'E'), + 0x1000000000000000..=0xffffffffffffffff => (kib >> 60, 'Z'), + }; + format!("{} {}iB", mem, unit).into_boxed_str() } fn extract_value(line: &str) -> Result> {