tuwunel_core/log/fmt_span.rs
1//! Parsing for tracing span-lifecycle formatting modes.
2//!
3//! Known text values map case-insensitively to `FmtSpan` flags. Unknown values
4//! return `FmtSpan::NONE` in the error variant.
5
6use tracing_subscriber::fmt::format::FmtSpan;
7
8use crate::Result;
9
10/// Parses a tracing span-lifecycle mode without case sensitivity.
11///
12/// Recognized names map to the corresponding `FmtSpan` flag. Unknown names
13/// return `FmtSpan::NONE` on the error side for use as a fallback.
14#[inline]
15pub fn from_str(str: &str) -> Result<FmtSpan, FmtSpan> {
16 match str.to_uppercase().as_str() {
17 | "ENTER" => Ok(FmtSpan::ENTER),
18 | "EXIT" => Ok(FmtSpan::EXIT),
19 | "NEW" => Ok(FmtSpan::NEW),
20 | "CLOSE" => Ok(FmtSpan::CLOSE),
21 | "ACTIVE" => Ok(FmtSpan::ACTIVE),
22 | "FULL" => Ok(FmtSpan::FULL),
23 | "NONE" => Ok(FmtSpan::NONE),
24 | _ => Err(FmtSpan::NONE),
25 }
26}