shape_runtime/print_result.rs
1//! Output formatting carriers — `PrintResult` and `PrintSpan`.
2//!
3//! Per ADR-006 §2.7.4 (output adapter ruling), these types live in
4//! `shape-runtime` rather than `shape-value`. They are runtime-tier
5//! formatting concerns with no value-tier dependency: the structure carries
6//! a rendered string and a vector of spans (literals or value references),
7//! and is consumed by the [`crate::output_adapter::OutputAdapter`] trait.
8//!
9//! The pre-bulldozer placement under `shape-value` (as the
10//! `RareHeapData::PrintResult` arm) was load-bearing only because
11//! `ValueWord::from_print_result` returned a tagged heap pointer to a
12//! `PrintResult`. After `ValueWord` deletion, output adapters return a
13//! [`shape_value::KindedSlot`] directly; the `PrintResult` carrier moves
14//! up to the runtime tier where it is consumed.
15
16/// A single span within a rendered print() output.
17///
18/// Spans capture either literal text (no value reference) or formatted
19/// output for a specific source-level value. Used by the REPL to enable
20/// post-execution reformatting via `:reformat`.
21#[derive(Debug, Clone)]
22pub enum PrintSpan {
23 /// Literal text emitted by the formatter (no value reference).
24 Literal {
25 text: String,
26 start: usize,
27 end: usize,
28 span_id: String,
29 },
30 /// Formatted output for a specific value, with the source expression
31 /// preserved so the REPL can re-render with a different format spec.
32 Value {
33 text: String,
34 start: usize,
35 end: usize,
36 span_id: String,
37 source_expr: String,
38 },
39}
40
41/// Output of a `print()` call: rendered string plus per-span metadata.
42///
43/// The `rendered` field is the fully formatted string ready for stdout.
44/// `spans` lets REPL-mode adapters preserve enough metadata to rerender
45/// individual values without re-evaluating the whole expression.
46#[derive(Debug, Clone)]
47pub struct PrintResult {
48 pub rendered: String,
49 pub spans: Vec<PrintSpan>,
50}