Code Example Template
enum ShortcutAction {
    Remap(u32),
    RunScript(PathBuf),
    Macro(Vec<u32>),
}

Deep-Dive System Documentation

Algebraic Data Carrying Enums

Unlike simple enum values, Rust variants can carry nested data, turning enums into algebraic sum types (tagged unions).

Defining Nested Action Sets

In shortcut and launcher engines, actions behave polymorphically. Using data-enums, this is structured safely without resorting to dynamic pointer casting or interface inheritance:

use std::path::PathBuf;

enum ShortcutAction {
    Remap(u32),          // Single VK key remap code
    RunScript(PathBuf),  // Absolute path to run
    Macro(Vec<u32>),     // Consequent list of virtual key clicks
}

let trigger = ShortcutAction::RunScript(PathBuf::from("/bin/tool"));

Memory Packing Rules

  • Storage Size: Equal to the size of the largest variant plus the enum's 1-byte discriminant tag (plus padding for alignment).
  • Nesting: Ideal for building finite state machines or abstract execution trees.

Exhaustive Branching

When matching a data-enum variant, you can destructure the internal parameters directly, providing high compile-time safety.

Quick Reference Guide

enum Message { Quit, Move { x: i32, y: i32 } }
let msg = Message::Quit;