diff --git a/shared/Cargo.toml b/shared/Cargo.toml index ae57b40..baa841b 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" [dependencies] build-info = "0.0.38" +log = "0.4.22" notmuch = { path = "../notmuch" } serde = { version = "1.0.147", features = ["derive"] } diff --git a/shared/src/lib.rs b/shared/src/lib.rs index bd0a8de..9ff01d2 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -1,4 +1,7 @@ +use std::hash::{DefaultHasher, Hash, Hasher}; + use build_info::{BuildInfo, VersionControl}; +use log::info; use notmuch::SearchSummary; use serde::{Deserialize, Serialize}; @@ -49,3 +52,9 @@ pub fn build_version(bi: fn() -> &'static BuildInfo) -> String { format!("v{}{}", bi.crate_info.version, commit(&bi.version_control)).to_string() } +pub fn compute_color(data: &str) -> String { + info!("compute_color({data})"); + let mut hasher = DefaultHasher::new(); + data.hash(&mut hasher); + format!("#{:06x}", hasher.finish() % (1 << 24)) +}