#[non_exhaustive]pub struct OutputNode {
pub name: String,
pub entry_type: EntryType,
pub text: Option<String>,
pub cells: Vec<String>,
pub children: Vec<OutputNode>,
pub line: Option<u64>,
}Expand description
A node in the output tree.
All fields are always serialized (no skip_serializing_if) for predictable shape across JSON, postcard, and bincode formats.
text is Option<String> because None and Some(“”) are semantically distinct:
- None: this is a named entry (file listing, table row), not a text node
- Some(“”): this IS a text node whose content is empty (e.g.
echo "")
The is_text_only() method depends on this distinction.
#[non_exhaustive] for the same reason OutputData is: this struct grows
— line was added in 0.16 — and an out-of-tree struct literal would break
on each addition. Build one with OutputNode::new or
OutputNode::text and the builder methods.
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.name: StringPrimary identifier (filename, key, label).
entry_type: EntryTypeRendering hint (colors, icons).
text: Option<String>Text content (for echo, cat, exec).
Three-state semantics:
None— named entry (file listing, table row), not textSome("")— text node with empty content (e.g.,echo "")Some("x")— text node with content
is_text_only() returns true iff text is Some AND name/cells/children are empty.
cells: Vec<String>Additional columns (for ls -l, ps, env).
children: Vec<OutputNode>Child nodes (for tree, find).
line: Option<u64>Which line of the file or stream this row is, 1-based.
The anchor a builtin declares and every consumer reads: --json
renders it as an integer named line, and the REPL and embedders read
the same field. None means the row has no line to point at (a
directory entry, a process, an environment variable), not line zero.
Set it with OutputNode::at_line. Do not re-derive it from cells —
a cell is a rendering choice, positional and per-builtin, and reading
one back is what this field exists to stop.
Implementations§
Source§impl OutputNode
impl OutputNode
Sourcepub fn new(name: impl Into<String>) -> OutputNode
pub fn new(name: impl Into<String>) -> OutputNode
Create a new node with a name.
Sourcepub fn text(content: impl Into<String>) -> OutputNode
pub fn text(content: impl Into<String>) -> OutputNode
Create a text-only node (for echo, cat, etc.).
Sourcepub fn with_entry_type(self, entry_type: EntryType) -> OutputNode
pub fn with_entry_type(self, entry_type: EntryType) -> OutputNode
Set the entry type for rendering hints.
Sourcepub fn at_line(self, line: u64) -> OutputNode
pub fn at_line(self, line: u64) -> OutputNode
Declare which line of the file or stream this row is, 1-based.
A builtin says which line; the kernel decides how to render it.
use kaish_types::OutputNode;
let node = OutputNode::new("fn main() {").at_line(42);
assert_eq!(node.line, Some(42));Sourcepub fn with_cells(self, cells: Vec<String>) -> OutputNode
pub fn with_cells(self, cells: Vec<String>) -> OutputNode
Set additional columns for tabular output.
Sourcepub fn with_children(self, children: Vec<OutputNode>) -> OutputNode
pub fn with_children(self, children: Vec<OutputNode>) -> OutputNode
Set child nodes for tree output.
Sourcepub fn with_text(self, text: impl Into<String>) -> OutputNode
pub fn with_text(self, text: impl Into<String>) -> OutputNode
Set text content.
Sourcepub fn is_text_only(&self) -> bool
pub fn is_text_only(&self) -> bool
Check if this is a text-only node.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Check if this node has children.
Sourcepub fn estimated_byte_size(&self) -> usize
pub fn estimated_byte_size(&self) -> usize
Estimate brace-notation byte size without materializing.
Sourcepub fn write_canonical(
&self,
w: &mut dyn Write,
budget: usize,
) -> Result<usize, Error>
pub fn write_canonical( &self, w: &mut dyn Write, budget: usize, ) -> Result<usize, Error>
Write brace-notation to a writer. Returns bytes written.
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
Get the display name, potentially with text content.
Trait Implementations§
Source§impl Clone for OutputNode
impl Clone for OutputNode
Source§fn clone(&self) -> OutputNode
fn clone(&self) -> OutputNode
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 OutputNode
impl Debug for OutputNode
Source§impl Default for OutputNode
impl Default for OutputNode
Source§fn default() -> OutputNode
fn default() -> OutputNode
Source§impl<'de> Deserialize<'de> for OutputNodewhere
OutputNode: Default,
impl<'de> Deserialize<'de> for OutputNodewhere
OutputNode: Default,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<OutputNode, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<OutputNode, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for OutputNode
Source§impl PartialEq for OutputNode
impl PartialEq for OutputNode
Source§impl Serialize for OutputNode
impl Serialize for OutputNode
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for OutputNode
Auto Trait Implementations§
impl Freeze for OutputNode
impl RefUnwindSafe for OutputNode
impl Send for OutputNode
impl Sync for OutputNode
impl Unpin for OutputNode
impl UnsafeUnpin for OutputNode
impl UnwindSafe for OutputNode
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> ⓘ
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
Source§impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
Source§fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
WrappingSpan::make_wrapped to wrap an AST node in a span.