sayiir_core/branch_key.rs
1//! The `BranchKey` trait for type-safe conditional branching.
2//!
3//! Implement this trait on a fieldless enum to constrain the routing keys
4//! that a `route` node can produce. The derive macro
5//! `BranchKey` (from `sayiir-macros`) generates the implementation
6//! automatically.
7//!
8//! # Example
9//!
10//! ```rust
11//! use sayiir_core::branch_key::BranchKey;
12//!
13//! enum Intent {
14//! Billing,
15//! Tech,
16//! }
17//!
18//! impl BranchKey for Intent {
19//! fn as_key(&self) -> &'static str {
20//! match self {
21//! Intent::Billing => "billing",
22//! Intent::Tech => "tech",
23//! }
24//! }
25//!
26//! fn all_keys() -> &'static [&'static str] {
27//! &["billing", "tech"]
28//! }
29//! }
30//! ```
31
32/// A routing key for conditional branching.
33///
34/// Implementors are fieldless enums whose variants map 1-to-1 to the named
35/// branches in a `route` node. The builder uses [`all_keys`](BranchKey::all_keys)
36/// to verify exhaustiveness at build time.
37pub trait BranchKey: Send + Sync + 'static {
38 /// The string key corresponding to this variant.
39 fn as_key(&self) -> &'static str;
40
41 /// All possible keys for this type (one per variant).
42 fn all_keys() -> &'static [&'static str];
43}