#[non_exhaustive]pub struct OutputData {
pub headers: Option<Vec<String>>,
pub root: Vec<OutputNode>,
pub rich_json: Option<Value>,
}Expand description
Structured output data from a command.
This is the top-level structure for command output. It contains optional column headers and a list of root nodes.
headers is Option<Vec
§Rendering Rules
| Structure | Interactive | Piped/Model |
|---|---|---|
Single node with text | Print text | Print text |
Flat nodes, name only | Multi-column, colored | One per line |
Flat nodes with cells | Aligned table | TSV or names only |
Nested children | Box-drawing tree | Brace notation |
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.headers: Option<Vec<String>>Column headers (optional, for table output).
root: Vec<OutputNode>Top-level nodes.
rich_json: Option<Value>Render-only override for --json consumers. When Some,
to_json() returns this verbatim instead of inferring from
headers / root / cells. Use it when a builtin wants its
--json shape to be richer than the table form (e.g. grep
emitting per-match objects with submatches and byte offsets).
Skipped by serde (and thus by postcard / bincode) — this is a transient render hint, not part of the persisted shape.
Implementations§
Source§impl OutputData
impl OutputData
Sourcepub fn text(content: impl Into<String>) -> Self
pub fn text(content: impl Into<String>) -> Self
Create output data with a single text node.
This is the simplest form for commands like echo.
Sourcepub fn nodes(nodes: Vec<OutputNode>) -> Self
pub fn nodes(nodes: Vec<OutputNode>) -> Self
Create output data with named nodes (for ls, etc.).
Sourcepub fn table(headers: Vec<String>, nodes: Vec<OutputNode>) -> Self
pub fn table(headers: Vec<String>, nodes: Vec<OutputNode>) -> Self
Create output data with headers and nodes (for ls -l, ps, etc.).
Sourcepub fn with_headers(self, headers: Vec<String>) -> Self
pub fn with_headers(self, headers: Vec<String>) -> Self
Set column headers.
Sourcepub fn with_rich_json(self, value: Value) -> Self
pub fn with_rich_json(self, value: Value) -> Self
Attach a render-only --json override. See rich_json field doc.
Sourcepub fn is_simple_text(&self) -> bool
pub fn is_simple_text(&self) -> bool
Check if this output is simple text (single text-only node).
Sourcepub fn is_tabular(&self) -> bool
pub fn is_tabular(&self) -> bool
Check if this output has tabular data (nodes with cells).
Sourcepub fn into_text(self) -> Result<String, Self>
pub fn into_text(self) -> Result<String, Self>
Extract the owned String from a single-text-node OutputData.
Returns Err(self) for non-simple-text output (tables, trees, multi-node),
giving the caller back the unconsumed OutputData.
Sourcepub fn estimated_byte_size(&self) -> usize
pub fn estimated_byte_size(&self) -> usize
Estimate canonical string byte size without materializing.
Lower bound — actual may be slightly larger due to formatting.
Mirrors to_canonical_string() structure but only accumulates sizes.
Sourcepub fn write_canonical(
&self,
w: &mut dyn Write,
budget: Option<usize>,
) -> Result<usize>
pub fn write_canonical( &self, w: &mut dyn Write, budget: Option<usize>, ) -> Result<usize>
Write canonical representation to a writer with optional byte budget.
Returns total bytes written. Stops after budget exceeded (imprecise: one write past the limit is fine — caller uses this for spill detection, not for exact truncation).
Sourcepub fn to_canonical_string(&self) -> String
pub fn to_canonical_string(&self) -> String
Convert to canonical string output (for pipes).
This produces a simple string representation suitable for piping to other commands:
- Text nodes: their text content
- Named nodes: names joined by newlines
- Tabular nodes (name + cells): TSV format (name\tcell1\tcell2…)
- Nested nodes: brace notation
Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
Serialize to a JSON value for --json flag handling.
Bare data, no envelope — optimized for jq patterns.
| Structure | JSON |
|---|---|
| Simple text | "hello world" |
| Flat list (names only) | ["file1", "file2"] |
| Table (headers + cells) | [{"col1": "v1", ...}, ...] |
| Tree (nested children) | {"dir": {"file": null}} |
Trait Implementations§
Source§impl Clone for OutputData
impl Clone for OutputData
Source§fn clone(&self) -> OutputData
fn clone(&self) -> OutputData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OutputData
impl Debug for OutputData
Source§impl Default for OutputData
impl Default for OutputData
Source§fn default() -> OutputData
fn default() -> OutputData
Source§impl<'de> Deserialize<'de> for OutputDatawhere
OutputData: Default,
impl<'de> Deserialize<'de> for OutputDatawhere
OutputData: Default,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for OutputData
Source§impl PartialEq for OutputData
impl PartialEq for OutputData
Source§fn eq(&self, other: &OutputData) -> bool
fn eq(&self, other: &OutputData) -> bool
self and other values to be equal, and is used by ==.