This is a custom status bar using the swaybar protocol, each block is an async function. Because of how the swaybar protocol works, every block update forces all blocks to be updated, but using async means that less work is wasted on the bar side of things.
The code in main.rs should be fairly self explanatory if you want to modify this to your liking.
Run
cargo install --path .then in your sway bar config, set:
swaybar_command sway_status_bar
Default binary size is ~500K. If you're interested in getting a smaller binary (174K on my laptop), then the following build options are the best I have found, without resorting to #![no_std] etc.:
RUSTFLAGS="-Ctarget-cpu=native \
-Zunstable-options \
-Zlocation-detail=none \
-Zfmt-debug=none \
-Cpanic=immediate-abort" \
\
cargo +nightly install --path . \
-Z build-std=std,panic_abort \
-Z build-std-features="optimize_for_size" \
--target $(rustc --print host-tuple)-Ctarget-cpu=nativetargets your particular CPU, rather than just architecture. This enables use of special instruction sets where applicable (probably mostly JSON serialization), which can help minimise assembly.-Zlocation-detail=noneremoves location detail forpanic!()and[track_caller]. Since we're not planning onpanic!ing, that's fine.-Zfmt-debug=noneturns{:?}into a no-op. This will break any blocks that rely on debug formatting for some reason.-Z panic=immediate-abortremoves panic formatting. This requiresbuild-std.-Z build-std=std,panic_abort -Z build-std-features="optimize_for_size" --target $(rustc --print host-tuple)compiles the standard library, selecting algorithms which optimise for size,panic_abortcauses panics insidestdtoabortrather thanunwind. For some reason,corefails to compile withpanic_abortif you don't pass a--target.
See min-sized-rust for information about these tricks and more
Issues and PRs welcome.