statum-core 0.9.0

Core types for representing legal workflow and protocol states explicitly in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
use super::MachineGraph;

/// Stable schema version for exported graph metadata.
///
/// The JSON representation is a lower-case string so external tools can branch
/// on it without depending on Rust enum names.
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum StableGraphMetadataVersion {
    /// Initial stable graph metadata shape.
    #[serde(rename = "v1")]
    V1,
}

/// Semantic authority level claimed by a `StableGraphMetadata` document.
///
/// This records the observation point for the generated graph. It is not a
/// claim over arbitrary Rust semantics or runtime behavior.
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum GraphAuthorityLevel {
    /// The graph was observed from the cfg-pruned attribute macro input and the
    /// supported return-type shapes Statum knows how to interpret.
    CfgPrunedMacroInput,
}

/// Known semantic cases this stable graph metadata model does not claim to
/// represent.
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum UnsupportedGraphMetadataCase {
    /// Transitions created or selected only by runtime values are outside the
    /// static graph. Runtime recordings can be joined back to known transition
    /// ids, but they cannot add new graph edges.
    RuntimeOnlyTransitions,
    /// Cfg-pruned source is the observation point. Ambiguous aliases or return
    /// shapes that depend on unsupported nested cfg patterns are rejected before
    /// stable metadata is produced.
    CfgAmbiguousAliases,
    /// Custom decision enums or aliases that are not one of Statum's supported
    /// wrapper shapes are rejected before this metadata is produced.
    UnexpandedCustomDecisionEnums,
    /// Items or aliases produced only by macro expansion are outside Statum's
    /// source-level transition target observation point.
    MacroGeneratedItems,
    /// Items or aliases produced only by `include!` expansion are outside
    /// Statum's source-level transition target observation point.
    IncludeGeneratedItems,
    /// Field-level labels/descriptions/metadata are reserved in the JSON shape,
    /// but current graph emission does not populate them.
    FieldLevelPresentationMetadata,
}

/// Stable Rust and JSON metadata shape for one Statum machine graph.
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct StableGraphMetadata {
    /// Schema version for this document.
    pub version: StableGraphMetadataVersion,
    /// Semantic observation point the graph is allowed to claim.
    pub authority: GraphAuthorityLevel,
    /// Cases intentionally absent from this shape or rejected by macro
    /// generation before a graph is emitted.
    pub unsupported_cases: Vec<UnsupportedGraphMetadataCase>,
    /// Machine-level metadata.
    pub machine: StableMachineMetadata,
    /// State metadata in graph order.
    pub states: Vec<StableStateMetadata>,
    /// Transition metadata in graph order.
    pub transitions: Vec<StableTransitionMetadata>,
}

/// Stable machine-readable graph invariant lint code.
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum GraphLintCode {
    /// A terminal-looking state name owns an outgoing transition.
    TerminalStateHasOutgoingTransition,
    /// A state cannot be reached from the first exported state through exported transitions.
    UnreachableState,
    /// A non-initial state has no incoming exported transition.
    MissingIncomingPath,
    /// A transition can return to its own source state.
    SuspiciousSelfTransition,
}

/// One graph invariant lint finding produced from stable metadata.
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct GraphLintFinding {
    /// Stable machine-readable lint code.
    pub code: GraphLintCode,
    /// Human-readable lint explanation.
    pub message: String,
    /// State associated with the finding when applicable.
    pub state: Option<String>,
    /// Transition associated with the finding when applicable.
    pub transition: Option<String>,
}

impl GraphLintCode {
    fn as_str(self) -> &'static str {
        match self {
            Self::TerminalStateHasOutgoingTransition => "terminal_state_has_outgoing_transition",
            Self::UnreachableState => "unreachable_state",
            Self::MissingIncomingPath => "missing_incoming_path",
            Self::SuspiciousSelfTransition => "suspicious_self_transition",
        }
    }
}

impl GraphAuthorityLevel {
    fn as_str(self) -> &'static str {
        match self {
            Self::CfgPrunedMacroInput => "cfg_pruned_macro_input",
        }
    }
}

const GRAPH_LINT_FALSE_POSITIVE_BOUNDARY: &str = "lints inspect only StableGraphMetadata; runtime-only policy, external guard conditions, and transition sites rejected before metadata emission are outside this report.";

impl StableGraphMetadata {
    /// Renders this stable graph metadata as a Mermaid state diagram.
    ///
    /// The diagram is generated only from this metadata document. It does not
    /// re-inspect source code or claim stronger semantic authority than the
    /// metadata's recorded `authority` field.
    pub fn to_mermaid_state_diagram(&self) -> String {
        let mut output = String::from("stateDiagram-v2\n");
        output.push_str("    %% machine: ");
        output.push_str(&escape_mermaid_comment(&self.machine.rust_type_path));
        output.push('\n');

        for (index, state) in self.states.iter().enumerate() {
            output.push_str("    state \"");
            output.push_str(&escape_mermaid_label(
                state.label.as_deref().unwrap_or(&state.rust_name),
            ));
            output.push_str("\" as s");
            output.push_str(&index.to_string());
            output.push('\n');
        }

        let mut unknown_states: Vec<&str> = Vec::new();
        for transition in &self.transitions {
            let Some(from_index) = self.state_index(&transition.from_state) else {
                continue;
            };

            for target in &transition.to_states {
                output.push_str("    s");
                output.push_str(&from_index.to_string());
                output.push_str(" --> ");
                match self.state_index(target) {
                    Some(target_index) => {
                        output.push('s');
                        output.push_str(&target_index.to_string());
                    }
                    None => {
                        let unknown_index = unknown_state_index(&mut unknown_states, target);
                        output.push_str("unknown_");
                        output.push_str(&unknown_index.to_string());
                    }
                }
                output.push_str(": ");
                output.push_str(&escape_mermaid_edge_label(
                    transition
                        .label
                        .as_deref()
                        .unwrap_or(&transition.method_name),
                ));
                output.push('\n');
            }
        }

        for (index, state_name) in unknown_states.iter().enumerate() {
            output.push_str("    state \"");
            output.push_str(&escape_mermaid_label(state_name));
            output.push_str("\" as unknown_");
            output.push_str(&index.to_string());
            output.push('\n');
        }

        output
    }

    /// Renders this stable graph metadata as a Graphviz DOT directed graph.
    ///
    /// The DOT document is emitted from graph-order metadata with stable node ids
    /// (`s0`, `s1`, ...) so repeated runs over the same metadata produce byte-for-
    /// byte identical output. It does not re-inspect source code or claim stronger
    /// semantic authority than the metadata's recorded `authority` field.
    pub fn to_dot_graph(&self) -> String {
        let mut output = String::from("digraph statum_workflow {\n");
        output.push_str("    graph [label=\"");
        output.push_str(&escape_dot_string(&self.machine.rust_type_path));
        output.push_str("\", labelloc=\"t\"];\n");
        output.push_str("    node [shape=\"box\"];\n");

        for (index, state) in self.states.iter().enumerate() {
            output.push_str("    s");
            output.push_str(&index.to_string());
            output.push_str(" [label=\"");
            output.push_str(&escape_dot_string(
                state.label.as_deref().unwrap_or(&state.rust_name),
            ));
            output.push_str("\"];\n");
        }

        let mut unknown_states: Vec<&str> = Vec::new();
        for transition in &self.transitions {
            let Some(from_index) = self.state_index(&transition.from_state) else {
                continue;
            };

            for target in &transition.to_states {
                output.push_str("    s");
                output.push_str(&from_index.to_string());
                output.push_str(" -> ");
                match self.state_index(target) {
                    Some(target_index) => {
                        output.push('s');
                        output.push_str(&target_index.to_string());
                    }
                    None => {
                        let unknown_index = unknown_state_index(&mut unknown_states, target);
                        output.push_str("unknown_");
                        output.push_str(&unknown_index.to_string());
                    }
                }
                output.push_str(" [label=\"");
                output.push_str(&escape_dot_string(
                    transition
                        .label
                        .as_deref()
                        .unwrap_or(&transition.method_name),
                ));
                output.push_str("\"];\n");
            }
        }

        for (index, state_name) in unknown_states.iter().enumerate() {
            output.push_str("    unknown_");
            output.push_str(&index.to_string());
            output.push_str(" [label=\"");
            output.push_str(&escape_dot_string(state_name));
            output.push_str("\"];\n");
        }

        output.push_str("}\n");
        output
    }

    /// Renders this stable graph metadata as a Markdown transition matrix.
    ///
    /// Rows are source states, columns are target states, and each cell is either
    /// a comma-separated list of transition labels/methods allowed from that
    /// source to that target or the literal `forbidden`. The table is generated
    /// only from this metadata document and claims no stronger authority than the
    /// metadata's recorded `authority` field.
    pub fn to_transition_matrix_table(&self) -> String {
        let mut cells = vec![
            vec![Vec::<&StableTransitionMetadata>::new(); self.states.len()];
            self.states.len()
        ];

        for transition in &self.transitions {
            let Some(from_index) = self.state_index(&transition.from_state) else {
                continue;
            };

            for target in &transition.to_states {
                if let Some(target_index) = self.state_index(target) {
                    cells[from_index][target_index].push(transition);
                }
            }
        }

        let mut output = String::new();
        output.push_str("| from \\ to |");
        for state in &self.states {
            output.push(' ');
            output.push_str(&escape_markdown_table_cell(
                state.label.as_deref().unwrap_or(&state.rust_name),
            ));
            output.push_str(" |");
        }
        output.push('\n');

        output.push_str("| --- |");
        for _ in &self.states {
            output.push_str(" --- |");
        }
        output.push('\n');

        for (from_index, state) in self.states.iter().enumerate() {
            output.push_str("| ");
            output.push_str(&escape_markdown_table_cell(
                state.label.as_deref().unwrap_or(&state.rust_name),
            ));
            output.push_str(" |");

            for target_cell in &cells[from_index] {
                output.push(' ');
                if target_cell.is_empty() {
                    output.push_str("forbidden");
                } else {
                    let labels = target_cell
                        .iter()
                        .map(|transition| {
                            escape_markdown_table_cell(
                                transition
                                    .label
                                    .as_deref()
                                    .unwrap_or(&transition.method_name),
                            )
                        })
                        .collect::<Vec<_>>()
                        .join(", ");
                    output.push_str(&labels);
                }
                output.push_str(" |");
            }
            output.push('\n');
        }

        output
    }

    /// Lints this stable graph metadata for structural invariant smells.
    ///
    /// These checks observe only this metadata document. They intentionally use
    /// conservative graph-order and naming heuristics for prototype tooling, so
    /// findings are warnings and may be false positives when runtime policy or
    /// unsupported macro shapes carry stronger semantics than the exported graph.
    pub fn lint_graph_invariants(&self) -> Vec<GraphLintFinding> {
        let mut findings = Vec::new();
        let state_names = self
            .states
            .iter()
            .map(|state| state.rust_name.as_str())
            .collect::<Vec<_>>();

        for transition in &self.transitions {
            if terminal_like_state_name(&transition.from_state) {
                findings.push(GraphLintFinding {
                    code: GraphLintCode::TerminalStateHasOutgoingTransition,
                    message: format!(
                        "state `{}` has outgoing transition `{}`; terminal-state lint treats terminal-looking state names as terminal candidates.",
                        transition.from_state, transition.method_name
                    ),
                    state: Some(transition.from_state.clone()),
                    transition: Some(transition.method_name.clone()),
                });
            }

            if transition
                .to_states
                .iter()
                .any(|target| target == &transition.from_state)
            {
                findings.push(GraphLintFinding {
                    code: GraphLintCode::SuspiciousSelfTransition,
                    message: format!(
                        "transition `{}` can return from `{}` to itself; verify the loop is intentional.",
                        transition.method_name, transition.from_state
                    ),
                    state: Some(transition.from_state.clone()),
                    transition: Some(transition.method_name.clone()),
                });
            }
        }

        for state_name in state_names.iter().skip(1) {
            if !self.transitions.iter().any(|transition| {
                transition
                    .to_states
                    .iter()
                    .any(|target| target == state_name)
            }) {
                findings.push(GraphLintFinding {
                    code: GraphLintCode::MissingIncomingPath,
                    message: format!(
                        "state `{state_name}` has no incoming exported transition; graph-order lint treats the first state as the root."
                    ),
                    state: Some((*state_name).to_owned()),
                    transition: None,
                });
            }
        }

        let reachable = self.reachable_state_names_from_first_state();
        for state_name in state_names.iter().skip(1) {
            if !reachable.iter().any(|reachable| reachable == state_name) {
                findings.push(GraphLintFinding {
                    code: GraphLintCode::UnreachableState,
                    message: format!(
                        "state `{state_name}` is not reachable from the first exported state through exported transitions."
                    ),
                    state: Some((*state_name).to_owned()),
                    transition: None,
                });
            }
        }

        findings
    }

    /// Renders graph invariant lint findings as deterministic text for CLI and CI use.
    pub fn to_graph_lint_report(&self) -> String {
        let findings = self.lint_graph_invariants();
        let mut output = String::new();
        output.push_str("Graph invariant lint report for ");
        output.push_str(&escape_plain_text_report_field(
            &self.machine.rust_type_path,
        ));
        output.push('\n');
        output.push_str("authority: ");
        output.push_str(self.authority.as_str());
        output.push('\n');
        output.push_str("false-positive boundary: ");
        output.push_str(GRAPH_LINT_FALSE_POSITIVE_BOUNDARY);
        output.push_str("\n\n");

        if findings.is_empty() {
            output.push_str("No graph invariant warnings.\n");
            return output;
        }

        for finding in findings {
            output.push_str("- ");
            output.push_str(finding.code.as_str());
            output.push_str(": ");
            output.push_str(&escape_plain_text_report_field(&finding.message));
            output.push('\n');
        }

        output
    }

    fn reachable_state_names_from_first_state(&self) -> Vec<&str> {
        let Some(first_state) = self.states.first() else {
            return Vec::new();
        };
        let mut reachable = vec![first_state.rust_name.as_str()];
        let mut cursor = 0;

        while cursor < reachable.len() {
            let source = reachable[cursor];
            cursor += 1;
            for transition in self
                .transitions
                .iter()
                .filter(|transition| transition.from_state == source)
            {
                for target in &transition.to_states {
                    if self.state_index(target).is_some()
                        && !reachable.iter().any(|reachable| *reachable == target)
                    {
                        reachable.push(target);
                    }
                }
            }
        }

        reachable
    }

    fn state_index(&self, rust_name: &str) -> Option<usize> {
        self.states
            .iter()
            .position(|state| state.rust_name == rust_name)
    }

    /// Builds the stable external metadata document from Statum's typed graph.
    ///
    /// The conversion intentionally lowers typed ids into Rust names so the JSON
    /// shape is stable for tooling. It does not inspect function bodies, runtime
    /// values, or expanded Rust items outside the macro input that produced
    /// `graph`.
    pub fn from_graph<S, T>(graph: &MachineGraph<S, T>) -> Self
    where
        S: Copy + Eq + 'static,
        T: Copy + Eq + 'static,
    {
        let states = graph
            .states
            .iter()
            .map(|state| StableStateMetadata {
                rust_name: state.rust_name.to_owned(),
                label: None,
                description: None,
                has_data: state.has_data,
                fields: Vec::new(),
            })
            .collect();

        let transitions = graph
            .transitions
            .iter()
            .map(|transition| StableTransitionMetadata {
                method_name: transition.method_name.to_owned(),
                label: None,
                description: None,
                from_state: graph
                    .state(transition.from)
                    .map(|state| state.rust_name)
                    .unwrap_or("<unknown>")
                    .to_owned(),
                to_states: transition
                    .to
                    .iter()
                    .map(|target| {
                        graph
                            .state(*target)
                            .map(|state| state.rust_name)
                            .unwrap_or("<unknown>")
                            .to_owned()
                    })
                    .collect(),
            })
            .collect();

        Self {
            version: StableGraphMetadataVersion::V1,
            authority: GraphAuthorityLevel::CfgPrunedMacroInput,
            unsupported_cases: vec![
                UnsupportedGraphMetadataCase::RuntimeOnlyTransitions,
                UnsupportedGraphMetadataCase::CfgAmbiguousAliases,
                UnsupportedGraphMetadataCase::UnexpandedCustomDecisionEnums,
                UnsupportedGraphMetadataCase::MacroGeneratedItems,
                UnsupportedGraphMetadataCase::IncludeGeneratedItems,
                UnsupportedGraphMetadataCase::FieldLevelPresentationMetadata,
            ],
            machine: StableMachineMetadata {
                module_path: graph.machine.module_path.to_owned(),
                rust_type_path: graph.machine.rust_type_path.to_owned(),
                label: None,
                description: None,
                fields: Vec::new(),
            },
            states,
            transitions,
        }
    }
}

fn escape_plain_text_report_field(value: &str) -> String {
    value.replace(['\n', '\r', '\t'], " ")
}

fn terminal_like_state_name(state_name: &str) -> bool {
    let normalized = state_name.to_ascii_lowercase();
    matches!(
        normalized.as_str(),
        "complete" | "completed" | "done" | "final" | "terminal" | "published" | "archived"
    ) || normalized.ends_with("complete")
        || normalized.ends_with("completed")
        || normalized.ends_with("done")
        || normalized.ends_with("published")
        || normalized.ends_with("archived")
}

fn unknown_state_index<'a>(unknown_states: &mut Vec<&'a str>, state_name: &'a str) -> usize {
    match unknown_states
        .iter()
        .position(|unknown_state| *unknown_state == state_name)
    {
        Some(index) => index,
        None => {
            unknown_states.push(state_name);
            unknown_states.len() - 1
        }
    }
}

fn escape_mermaid_comment(value: &str) -> String {
    value.replace(['\n', '\r'], " ")
}

fn escape_mermaid_edge_label(value: &str) -> String {
    value.replace(['\n', '\r'], " ")
}

fn escape_mermaid_label(value: &str) -> String {
    let mut escaped = String::new();
    for character in value.chars() {
        match character {
            '\\' => escaped.push_str("\\\\"),
            '"' => escaped.push_str("\\\""),
            '\n' | '\r' => escaped.push(' '),
            other => escaped.push(other),
        }
    }
    escaped
}

fn escape_dot_string(value: &str) -> String {
    let mut escaped = String::new();
    for character in value.chars() {
        match character {
            '\\' => escaped.push_str("\\\\"),
            '"' => escaped.push_str("\\\""),
            '\n' | '\r' => escaped.push_str("\\n"),
            other => escaped.push(other),
        }
    }
    escaped
}

fn escape_markdown_table_cell(value: &str) -> String {
    let mut escaped = String::new();
    for character in value.chars() {
        match character {
            '\\' => escaped.push_str("\\\\"),
            '|' => escaped.push_str("\\|"),
            '\n' | '\r' => escaped.push(' '),
            other => escaped.push(other),
        }
    }
    escaped
}

/// Stable machine-level metadata.
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct StableMachineMetadata {
    /// `module_path!()` for the source module that owns the machine.
    pub module_path: String,
    /// Fully qualified Rust type path for the machine family.
    pub rust_type_path: String,
    /// Optional human-facing label when a presentation layer supplies one.
    pub label: Option<String>,
    /// Optional human-facing description when a presentation layer supplies one.
    pub description: Option<String>,
    /// Reserved field metadata. Current graph emission leaves this empty.
    pub fields: Vec<StableFieldMetadata>,
}

/// Stable state-level metadata.
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct StableStateMetadata {
    /// Rust marker/variant name for the state.
    pub rust_name: String,
    /// Optional human-facing label when a presentation layer supplies one.
    pub label: Option<String>,
    /// Optional human-facing description when a presentation layer supplies one.
    pub description: Option<String>,
    /// Whether the state carries `state_data`.
    pub has_data: bool,
    /// Reserved state payload field metadata. Current graph emission leaves this
    /// empty because field-level presentation metadata is unsupported.
    pub fields: Vec<StableFieldMetadata>,
}

/// Stable transition-site metadata.
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct StableTransitionMetadata {
    /// Rust method name for the transition site.
    pub method_name: String,
    /// Optional human-facing label when a presentation layer supplies one.
    pub label: Option<String>,
    /// Optional human-facing description when a presentation layer supplies one.
    pub description: Option<String>,
    /// Rust state name of the exact source state.
    pub from_state: String,
    /// Rust state names of the exact legal target states.
    pub to_states: Vec<String>,
}

/// Reserved stable field metadata shape.
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct StableFieldMetadata {
    /// Rust field name when available.
    pub rust_name: String,
    /// Optional human-facing label when a presentation layer supplies one.
    pub label: Option<String>,
    /// Optional human-facing description when a presentation layer supplies one.
    pub description: Option<String>,
}