Skip to main content

EventEnum

Trait EventEnum 

Source
pub trait EventEnum:
    IntoBytes
    + Immutable
    + Copy {
    const REPR: u8;
    const LABELS: &'static [EnumLabel];
}
Expand description

A Rust enum usable as an event field.

Implemented by #[derive(EventEnum)] on a fieldless #[repr(u8|u16|u32|u64)] enum. Instead of hand-writing #[event(enum_labels(...))] on every field, you define the enum once with its strong type and pass it around; a field of that type is automatically reflected as a FieldType::Enum whose value→label map comes from LABELS. The IntoBytes + Immutable bounds let the enum sit inline in a #[repr(C)] event with no serialization.

use backbeat::EventEnum;
use backbeat::zerocopy::{Immutable, IntoBytes};

#[derive(EventEnum, IntoBytes, Immutable, Clone, Copy)]
#[repr(u8)]
enum Direction { Inbound = 0, Outbound = 1 }

Required Associated Constants§

Source

const REPR: u8

Width of the discriminant in bytes (1, 2, 4, or 8) — the enum’s #[repr] width.

Source

const LABELS: &'static [EnumLabel]

The value→label map for every variant, in declaration order.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§