From fd85c46b3afa35fb5bf7035b3218838b15b39828 Mon Sep 17 00:00:00 2001 From: CyndieKamau Date: Mon, 12 Aug 2024 23:34:29 +0300 Subject: [PATCH] chore: run cargo fmt for formatting --- backend/common/src/node_types.rs | 2 +- backend/telemetry_core/src/feed_message.rs | 16 ++++++++++------ backend/telemetry_core/src/state/chain_stats.rs | 8 ++++---- backend/telemetry_core/src/state/counter.rs | 10 ++-------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/backend/common/src/node_types.rs b/backend/common/src/node_types.rs index efc7001f3..5cafd1b7e 100644 --- a/backend/common/src/node_types.rs +++ b/backend/common/src/node_types.rs @@ -38,7 +38,7 @@ pub struct NodeDetails { pub validator: Option>, pub network_id: NetworkId, pub startup_time: Option>, - pub target_os: Option>, + pub target_os: Option>, pub target_arch: Option>, pub target_env: Option>, pub sysinfo: Option, diff --git a/backend/telemetry_core/src/feed_message.rs b/backend/telemetry_core/src/feed_message.rs index 017e59e24..2ba2a9180 100644 --- a/backend/telemetry_core/src/feed_message.rs +++ b/backend/telemetry_core/src/feed_message.rs @@ -17,8 +17,6 @@ //! This module provides a way of encoding the various messages that we'll //! send to subscribed feeds (browsers). - - use serde::Serialize; use crate::state::Node; @@ -187,9 +185,17 @@ impl FeedMessageWrite for AddedNode<'_> { let details = node.details(); // Always include sysinfo, conditionally include ip and hwbench based on expose_node_details. let node_hwbench = node.hwbench(); - let ip = if *expose_node_details { &details.ip } else { &None }; + let ip = if *expose_node_details { + &details.ip + } else { + &None + }; let sys_info = &details.sysinfo; - let hwbench = if *expose_node_details { &node_hwbench } else { &None }; + let hwbench = if *expose_node_details { + &node_hwbench + } else { + &None + }; let details = ( &details.name, @@ -218,11 +224,9 @@ impl FeedMessageWrite for AddedNode<'_> { } } - #[derive(Serialize)] pub struct ChainStatsUpdate<'a>(pub &'a ChainStats); - #[derive(Serialize, PartialEq, Eq, Default)] pub struct Ranking { pub list: Vec<(K, u64)>, diff --git a/backend/telemetry_core/src/state/chain_stats.rs b/backend/telemetry_core/src/state/chain_stats.rs index 74df55ead..be5c94676 100644 --- a/backend/telemetry_core/src/state/chain_stats.rs +++ b/backend/telemetry_core/src/state/chain_stats.rs @@ -144,7 +144,7 @@ pub struct ChainStatsCollator { linux_kernel: Counter, linux_distro: Counter, is_virtual_machine: Counter, - cpu_hashrate_score: Counter<(u32, Option),>, + cpu_hashrate_score: Counter<(u32, Option)>, memory_memcpy_score: Counter<(u32, Option)>, disk_sequential_write_score: Counter<(u32, Option)>, disk_random_write_score: Counter<(u32, Option)>, @@ -161,10 +161,10 @@ impl ChainStatsCollator { self.version.modify(Some(&*details.version), op); self.target_os - .modify(details.target_os.as_ref().map(|value| &**value), op); + .modify(details.target_os.as_ref().map(|value| &**value), op); self.target_arch - .modify(details.target_arch.as_ref().map(|value| &**value), op); + .modify(details.target_arch.as_ref().map(|value| &**value), op); let sysinfo = details.sysinfo.as_ref(); self.cpu.modify( @@ -178,7 +178,7 @@ impl ChainStatsCollator { self.memory.modify(memory.as_ref(), op); self.core_count - .modify(sysinfo.and_then(|sysinfo| sysinfo.core_count.as_ref()), op); + .modify(sysinfo.and_then(|sysinfo| sysinfo.core_count.as_ref()), op); self.linux_kernel.modify( sysinfo diff --git a/backend/telemetry_core/src/state/counter.rs b/backend/telemetry_core/src/state/counter.rs index b29e93eef..cc1f474c4 100644 --- a/backend/telemetry_core/src/state/counter.rs +++ b/backend/telemetry_core/src/state/counter.rs @@ -17,7 +17,6 @@ use crate::feed_message::Ranking; use std::collections::HashMap; - /// A data structure which counts how many occurrences of a given key we've seen. #[derive(Default)] pub struct Counter { @@ -28,7 +27,6 @@ pub struct Counter { /// The number of occurrences where the key is `None`. empty: u64, - } #[derive(Copy, Clone, PartialEq, Eq, Debug)] @@ -39,8 +37,7 @@ pub enum CounterValue { impl Counter where - K: Sized + std::hash::Hash + Eq - + K: Sized + std::hash::Hash + Eq, { /// Either adds or removes a single occurence of a given `key`. pub fn modify<'a, Q>(&mut self, key: Option<&'a Q>, op: CounterValue) @@ -54,7 +51,6 @@ where match op { CounterValue::Increment => { *entry += 1; - } CounterValue::Decrement => { *entry -= 1; @@ -67,9 +63,7 @@ where } else { assert_eq!(op, CounterValue::Increment); self.map.insert(key.to_owned(), 1); - } - } else { match op { CounterValue::Increment => { @@ -111,7 +105,7 @@ where /// Generates a sorted table of all of the keys. pub fn generate_ranking_ordered(&self) -> Ranking where - K: Copy + Clone + Ord + K: Copy + Clone + Ord, { let mut list: Vec<(K, u64)> = self.map.iter().map(|(key, count)| (*key, *count)).collect(); list.sort_unstable_by_key(|&(key, count)| (key, !count));