pub trait FromFieldValue:
Clone
+ Default
+ Send
+ Sync
+ Serialize
+ DeserializeOwned
+ 'static {
// Provided methods
fn from_str_value(s: &str) -> Option<Self> { ... }
fn from_u64_value(v: u64) -> Option<Self> { ... }
fn from_i64_value(v: i64) -> Option<Self> { ... }
fn from_bool_value(v: bool) -> Option<Self> { ... }
}Expand description
Trait for types that can be constructed from tracing field values.
Implement this for your context types to enable automatic field-to-context mapping.
§Example
use dcontext_tracing::FromFieldValue;
#[derive(Clone, Default, Debug, serde::Serialize, serde::Deserialize)]
struct RequestId(String);
impl FromFieldValue for RequestId {
fn from_str_value(s: &str) -> Option<Self> {
Some(RequestId(s.to_string()))
}
}Provided Methods§
Sourcefn from_str_value(s: &str) -> Option<Self>
fn from_str_value(s: &str) -> Option<Self>
Construct from a string value. Returns None if conversion fails.
Sourcefn from_u64_value(v: u64) -> Option<Self>
fn from_u64_value(v: u64) -> Option<Self>
Construct from a u64 value. Returns None if conversion fails.
Sourcefn from_i64_value(v: i64) -> Option<Self>
fn from_i64_value(v: i64) -> Option<Self>
Construct from an i64 value. Returns None if conversion fails.
Sourcefn from_bool_value(v: bool) -> Option<Self>
fn from_bool_value(v: bool) -> Option<Self>
Construct from a bool value. Returns None if conversion fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.