pub struct OutputData {
pub headers: Option<Vec<String>>,
pub root: Vec<OutputNode>,
}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.
§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§
§headers: Option<Vec<String>>Column headers (optional, for table output).
root: Vec<OutputNode>Top-level nodes.
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 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 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_toon(&self) -> String
pub fn to_toon(&self) -> String
Serialize to TOON format for --toon flag handling.
Converts to JSON value first, then encodes as TOON. TOON is ~40% fewer tokens than JSON for tabular data.
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 · 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 PartialEq for OutputData
impl PartialEq for OutputData
Source§impl Serialize for OutputData
impl Serialize for OutputData
impl StructuralPartialEq for OutputData
Auto Trait Implementations§
impl Freeze for OutputData
impl RefUnwindSafe for OutputData
impl Send for OutputData
impl Sync for OutputData
impl Unpin for OutputData
impl UnwindSafe for OutputData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more