Trait tfc::Enum

source ·
pub trait Enum: Copy + Clone + Eq + PartialEq + Display + Debug {
    const NAME: &'static str;
    const COUNT: u8;

    // Required methods
    fn display_name(&self) -> &'static str;
    fn identifier_name(&self) -> &'static str;
    fn from_u8(byte: u8) -> Option<Self>;
    fn into_u8(self) -> u8;

    // Provided method
    fn iter() -> EnumIterator<Self>  { ... }
}
Expand description

An enum with limited reflection capabilities.

The name of the enum itself and its variants is available. An iterator over the variants is also provided. The three enums that implement this trait are:

Examples

use tfc::{Key, Enum};

assert_eq!(Key::NAME, "Key");
assert_eq!(Key::PlayPause.identifier_name(), "PlayPause");
assert_eq!(Key::PlayPause.display_name(), "Play/Pause");

Required Associated Constants§

source

const NAME: &'static str

The name of the enum.

source

const COUNT: u8

The number of variants in the enum.

Required Methods§

source

fn display_name(&self) -> &'static str

The display name of this enum variant.

This is the name that is appropriate for showing to end users. It may contain spaces or other symbols and is in Title Case. It is used by the Display implementation.

source

fn identifier_name(&self) -> &'static str

The identifier name of this enum variant.

This is the raw identifier name of the enum variant in PascalCase. It is used by the Debug implementation.

source

fn from_u8(byte: u8) -> Option<Self>

Create an instance of the enum from a u8.

None is returned if the given byte is out of range (i.e. >= COUNT).

source

fn into_u8(self) -> u8

Convert this enum variant to a u8.

This is useful when casting a generic T: Enum to a u8.

Provided Methods§

source

fn iter() -> EnumIterator<Self>

Get an iterator over the variants of the enum.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Enum for CommandCode

source§

const NAME: &'static str = "CommandCode"

source§

const COUNT: u8 = 18u8

source§

impl Enum for Key

source§

const NAME: &'static str = "Key"

source§

const COUNT: u8 = 110u8

source§

impl Enum for MouseButton

source§

const NAME: &'static str = "MouseButton"

source§

const COUNT: u8 = 3u8