This commit is contained in:
Jan-Erik Rediger 2019-04-10 15:29:46 +02:00
Родитель 66c93eac28
Коммит bede7eb7c7
4 изменённых файлов: 12 добавлений и 11 удалений

Просмотреть файл

@ -6,7 +6,7 @@ lazy_static! {
pub static ref GLOBAL_METRIC: BooleanMetric = BooleanMetric::new(CommonMetricData { pub static ref GLOBAL_METRIC: BooleanMetric = BooleanMetric::new(CommonMetricData {
name: "global_metric".into(), name: "global_metric".into(),
category: "global".into(), category: "global".into(),
send_in_pings: vec!["core".into()], send_in_pings: vec!["core".into(), "metrics".into()],
lifetime: Lifetime::Ping, lifetime: Lifetime::Ping,
disabled: false, disabled: false,
}); });
@ -26,5 +26,6 @@ fn main() {
GLOBAL_METRIC.set(true); GLOBAL_METRIC.set(true);
local_metric.set("I can set this"); local_metric.set("I can set this");
println!("{}", storage::StorageManager.dump()); println!("Core Data:\n{}", storage::StorageManager.dump("core"));
println!("Metrics Data:\n{}", storage::StorageManager.dump("metrics"));
} }

Просмотреть файл

@ -26,7 +26,7 @@ impl BooleanStorageImpl {
} }
impl StorageDump for BooleanStorageImpl { impl StorageDump for BooleanStorageImpl {
fn dump(&self) -> Option<JsonValue> { fn dump(&self, store_name: &str) -> Option<JsonValue> {
self.store.get("core").map(|store| json!(store)) self.store.get(store_name).map(|store| json!(store))
} }
} }

Просмотреть файл

@ -18,16 +18,16 @@ lazy_static! {
} }
pub trait StorageDump { pub trait StorageDump {
fn dump(&self) -> Option<JsonValue>; fn dump(&self, store_name: &str) -> Option<JsonValue>;
} }
pub struct StorageManager; pub struct StorageManager;
macro_rules! dump_storages { macro_rules! dump_storages {
($(($name:expr, $storage:tt),)+) => {{ ($store_name:expr => $(( $name:expr, $storage:tt),)+) => {{
let data = json!({ let data = json!({
$( $(
$name: $storage.read().unwrap().dump(), $name: $storage.read().unwrap().dump($store_name),
)+ )+
}); });
data data
@ -35,8 +35,8 @@ macro_rules! dump_storages {
} }
impl StorageManager { impl StorageManager {
pub fn dump(&self) -> String { pub fn dump(&self, store_name: &str) -> String {
let data = dump_storages!(("bool", BooleanStorage), ("string", StringStorage),); let data = dump_storages!(store_name => ("bool", BooleanStorage), ("string", StringStorage),);
::serde_json::to_string_pretty(&data).unwrap() ::serde_json::to_string_pretty(&data).unwrap()
} }

Просмотреть файл

@ -26,7 +26,7 @@ impl StringStorageImpl {
} }
impl StorageDump for StringStorageImpl { impl StorageDump for StringStorageImpl {
fn dump(&self) -> Option<JsonValue> { fn dump(&self, store_name: &str) -> Option<JsonValue> {
self.store.get("core").map(|store| json!(store)) self.store.get(store_name).map(|store| json!(store))
} }
} }