Skip to main content

Key

Trait Key 

Source
pub trait Key:
    Copy
    + Eq
    + 'static {
    const MAX_KEYS: usize;
    const KEYS: &'static [Self];
    const KEY_STRS: &'static [&'static str];
    const DURATION_PATH: &'static [Self];
    const TIMESTAMP_PATH: &'static [Self];
    const ID_PATH: &'static [Self];
    const LOG_KEY: &'static str;
    const LEVEL_KEY: &'static str;
    const MESSAGE_KEY: &'static str;

    // Required methods
    fn as_str(self) -> &'static str;
    fn as_index(self) -> usize;
}
Expand description

Trait for wide-event keys.

Each variant of a key enum represents a JSON key in the wide event. The wide_log! macro generates the enum and this trait impl automatically from the JSON structure — users do not implement this trait manually.

§Path-Based Duration / Timestamp / ID

DURATION_PATH specifies the nested path to the duration field (e.g. [Duration, TotalMs]). The guard auto-sets this field to the elapsed time in milliseconds on drop.

TIMESTAMP_PATH specifies the nested path to the timestamp field (e.g. [Event, Timestamp]). The guard auto-sets this field to the current time as an RFC 3339 string on drop.

ID_PATH specifies the nested path to the id field (e.g. [Event, Id]). The builder auto-sets this field to the generated ID string on build().

The user does not define Log, Level, or Message variants. Log entries are handled entirely internally by a LogEntry type and the log_entries field on WideEvent.

Required Associated Constants§

Source

const MAX_KEYS: usize

The total number of keys in the enum.

Source

const KEYS: &'static [Self]

All keys in enum order, indexed by as_index.

Source

const KEY_STRS: &'static [&'static str]

All key strings in enum order, indexed by as_index. Used for O(1) as_str() via array index instead of a match.

Source

const DURATION_PATH: &'static [Self]

Path to the duration field (e.g. [Duration, TotalMs]). Auto-set by the guard on drop. The value is in milliseconds (u64).

Source

const TIMESTAMP_PATH: &'static [Self]

Path to the timestamp field (e.g. [Event, Timestamp]). Auto-set by the guard on drop. The value is an RFC 3339 string.

Source

const ID_PATH: &'static [Self]

Path to the id field (e.g. [Event, Id]). Auto-set by the builder on build(). The value is a string.

Source

const LOG_KEY: &'static str

JSON key for the log entries array. Override path: Log. Default: “log”.

Source

const LEVEL_KEY: &'static str

JSON key for the level field within each log entry. Override path: Log.Level. Default: “level”.

Source

const MESSAGE_KEY: &'static str

JSON key for the message field within each log entry. Override path: Log.Message. Default: “message”.

Required Methods§

Source

fn as_str(self) -> &'static str

Returns the JSON string representation of this key.

Source

fn as_index(self) -> usize

Returns the discriminant index of this key.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§