From caa559c99a52a0688429fb485618ef3fdabcf18b Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 15 Feb 2024 16:16:27 +0100 Subject: [PATCH] metrics: remove Histogram from MetricsError Public MetricsError enum contains a reference to `Histogram`. In fact, the `MetricsError::Poison` is never really constructed since we always unwrap the PoisonError when trying to acquire the mutex. This is why we get rid of the `MetricsError::Poison` enum value and convert the `MetricsError` enum to struct holding an error cause. --- scylla/src/transport/metrics.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/scylla/src/transport/metrics.rs b/scylla/src/transport/metrics.rs index 8bc5df554c..85f7ed4913 100644 --- a/scylla/src/transport/metrics.rs +++ b/scylla/src/transport/metrics.rs @@ -1,30 +1,23 @@ use histogram::Histogram; use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; +use std::sync::{Arc, Mutex}; const ORDER_TYPE: Ordering = Ordering::Relaxed; #[derive(Debug)] -pub enum MetricsError<'a> { - Poison(PoisonError>), - Histogram(&'static str), +pub struct MetricsError { + cause: &'static str, } -impl<'a> From>> for MetricsError<'a> { - fn from(err: PoisonError>) -> MetricsError { - MetricsError::Poison(err) - } -} - -impl From<&'static str> for MetricsError<'_> { +impl From<&'static str> for MetricsError { fn from(err: &'static str) -> MetricsError { - MetricsError::Histogram(err) + MetricsError { cause: err } } } -impl std::fmt::Display for MetricsError<'_> { +impl std::fmt::Display for MetricsError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self) + write!(f, "metrics error: {}", self.cause) } }