use strum instead

This commit is contained in:
Charles Hall 2024-06-04 12:34:09 -07:00
parent 786e68129d
commit 7076c13058
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 27 additions and 12 deletions

23
Cargo.lock generated
View file

@ -887,6 +887,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",
"sha-1", "sha-1",
"strum",
"thiserror", "thiserror",
"thread_local", "thread_local",
"tikv-jemallocator", "tikv-jemallocator",
@ -2790,6 +2791,28 @@ dependencies = [
"der", "der",
] ]
[[package]]
name = "strum"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946"
dependencies = [
"heck 0.4.1",
"proc-macro2",
"quote",
"rustversion",
"syn",
]
[[package]] [[package]]
name = "subslice" name = "subslice"
version = "0.2.3" version = "0.2.3"

View file

@ -129,6 +129,7 @@ serde_html_form = "0.2.6"
serde_json = { version = "1.0.117", features = ["raw_value"] } serde_json = { version = "1.0.117", features = ["raw_value"] }
serde_yaml = "0.9.34" serde_yaml = "0.9.34"
sha-1 = "0.10.1" sha-1 = "0.10.1"
strum = { version = "0.26.2", features = ["derive"] }
thiserror = "1.0.61" thiserror = "1.0.61"
thread_local = "1.1.8" thread_local = "1.1.8"
tikv-jemallocator = { version = "0.5.4", features = ["unprefixed_malloc_on_supported_platforms"], optional = true } tikv-jemallocator = { version = "0.5.4", features = ["unprefixed_malloc_on_supported_platforms"], optional = true }

View file

@ -18,6 +18,7 @@ use opentelemetry_sdk::{
metrics::{new_view, Aggregation, Instrument, SdkMeterProvider, Stream}, metrics::{new_view, Aggregation, Instrument, SdkMeterProvider, Stream},
Resource, Resource,
}; };
use strum::AsRefStr;
use tokio::time::Instant; use tokio::time::Instant;
use tracing_flame::{FlameLayer, FlushGuard}; use tracing_flame::{FlameLayer, FlushGuard};
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Layer, Registry}; use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Layer, Registry};
@ -41,7 +42,7 @@ impl Drop for Guard {
} }
/// Type to record cache performance in a tracing span field. /// Type to record cache performance in a tracing span field.
#[derive(Clone, Copy)] #[derive(Clone, Copy, AsRefStr)]
pub(crate) enum FoundIn { pub(crate) enum FoundIn {
/// Found in cache /// Found in cache
Cache, Cache,
@ -55,20 +56,10 @@ pub(crate) enum FoundIn {
} }
impl FoundIn { impl FoundIn {
/// Returns a stringified representation of the current value
fn as_str(self) -> &'static str {
match self {
FoundIn::Cache => "Cache",
FoundIn::Database => "Database",
FoundIn::Remote => "Remote",
FoundIn::Nothing => "Nothing",
}
}
/// Record the current value to the current [`tracing::Span`] /// Record the current value to the current [`tracing::Span`]
// TODO: use tracing::Value instead if it ever becomes accessible // TODO: use tracing::Value instead if it ever becomes accessible
pub(crate) fn record(self, field: &str) { pub(crate) fn record(self, field: &str) {
tracing::Span::current().record(field, self.as_str()); tracing::Span::current().record(field, self.as_ref());
} }
} }