Trait tor_dirmgr::event::FlagEvent

source ·
pub(crate) trait FlagEvent: Sized {
    const MAXIMUM: u16;

    // Required methods
    fn to_index(self) -> u16;
    fn from_index(flag: u16) -> Option<Self>;
}
Expand description

A trait to indicate something that can be published with FlagPublisher.

Since the implementation of FlagPublisher requires that its events be represented as small integers, this trait is mainly about converting to and from those integers.

Required Associated Constants§

source

const MAXIMUM: u16

The maximum allowed integer value that FlagEvent::to_index() can return for this type.

This is limited to u16 because the FlagPublisher uses a vector of all known flags, and sometimes iterates over the whole vector.

Required Methods§

source

fn to_index(self) -> u16

Convert this event into an index.

For efficiency, indices should be small and densely packed.

source

fn from_index(flag: u16) -> Option<Self>

Try to reconstruct an event from its index. Return None if the index is out-of-bounds.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FlagEvent for DirEvent

source§

const MAXIMUM: u16 = 1u16

source§

fn to_index(self) -> u16

source§

fn from_index(flag: u16) -> Option<Self>

source§

impl FlagEvent for BridgeDescEvent

source§

const MAXIMUM: u16 = 0u16

source§

fn to_index(self) -> u16

source§

fn from_index(flag: u16) -> Option<Self>

Implementors§