Trait Encodable
pub trait Encodable {
// Required method
fn encode(&self, encoder: &mut ThreadLocalEncoder<'_>);
}dial9 only.Expand description
Trait for types that can be encoded into a dial9 trace.
§Simple case — #[derive(TraceEvent)]
Any type implementing TraceEvent automatically
implements Encodable via a blanket impl, so you can pass it directly to
Dial9Handle::record_event:
#[derive(TraceEvent)]
struct MyEvent {
#[traceevent(timestamp)]
timestamp_ns: u64,
request_count: u32,
}
handle.record_event(MyEvent { timestamp_ns: now, request_count: 42 });§Advanced case — string interning
Implement Encodable manually when you need InternedString fields
for efficient repeated-string encoding:
struct HttpRequest { timestamp_ns: u64, method: String, status: u32 }
impl Encodable for HttpRequest {
fn encode(&self, enc: &mut ThreadLocalEncoder<'_>) {
let method = enc.intern_string(&self.method);
enc.encode(&HttpRequestWire {
timestamp_ns: self.timestamp_ns,
method,
status: self.status,
});
}
}§Wire event naming
The event name in the trace comes from the struct passed to
ThreadLocalEncoder::encode, not from the type implementing Encodable.
In the example above, the trace will contain events named "HttpRequestWire",
not "HttpRequest".
Required Methods§
fn encode(&self, encoder: &mut ThreadLocalEncoder<'_>)
fn encode(&self, encoder: &mut ThreadLocalEncoder<'_>)
Encode this event into the thread-local trace buffer.
Implementations should call ThreadLocalEncoder::encode exactly once.
Each encode call is counted as one event for buffer flush decisions;
calling encode multiple times will produce multiple wire events but
only one event will be counted.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".