mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 23:31:24 +01:00
use strum instead
This commit is contained in:
parent
792300d220
commit
9364d44ce2
3 changed files with 27 additions and 12 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
|
@ -887,6 +887,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"serde_yaml",
|
||||
"sha-1",
|
||||
"strum",
|
||||
"thiserror",
|
||||
"thread_local",
|
||||
"tikv-jemallocator",
|
||||
|
|
@ -2790,6 +2791,28 @@ dependencies = [
|
|||
"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]]
|
||||
name = "subslice"
|
||||
version = "0.2.3"
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ serde_html_form = "0.2.6"
|
|||
serde_json = { version = "1.0.117", features = ["raw_value"] }
|
||||
serde_yaml = "0.9.34"
|
||||
sha-1 = "0.10.1"
|
||||
strum = { version = "0.26.2", features = ["derive"] }
|
||||
thiserror = "1.0.61"
|
||||
thread_local = "1.1.8"
|
||||
tikv-jemallocator = { version = "0.5.4", features = ["unprefixed_malloc_on_supported_platforms"], optional = true }
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use opentelemetry_sdk::{
|
|||
metrics::{new_view, Aggregation, Instrument, SdkMeterProvider, Stream},
|
||||
Resource,
|
||||
};
|
||||
use strum::AsRefStr;
|
||||
use tokio::time::Instant;
|
||||
use tracing_flame::{FlameLayer, FlushGuard};
|
||||
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.
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, AsRefStr)]
|
||||
pub(crate) enum FoundIn {
|
||||
/// Found in cache
|
||||
Cache,
|
||||
|
|
@ -55,20 +56,10 @@ pub(crate) enum 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`]
|
||||
// TODO: use tracing::Value instead if it ever becomes accessible
|
||||
pub(crate) fn record(self, field: &str) {
|
||||
tracing::Span::current().record(field, self.as_str());
|
||||
tracing::Span::current().record(field, self.as_ref());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue