summary
Composes a titled block of count rows, an optional completion message, and an optional trailing hint. A dedicated empty-state message replaces the row block when no rows are pushed, letting callers hand a single component both the “nothing to do” and “here’s what happened” paths.
struct Component
pub struct ComponentRenders a titled summary block with per-row counts, plus optional completion and hint lines beneath it.
A single Component handles both outcomes a tally-style command needs to
print:
- When rows are pushed, the title is followed by an indented list of rows.
- When no rows are pushed and an
empty_messageis set, the empty message replaces the rows (the title is suppressed).
The optional SuccessMessage trailer and muted hint line render after the
summary block, separated by blank lines.
| Field | Type | Description |
|---|---|---|
empty_message |
Option<String> | Muted line shown instead of the title and rows when no row is pushed. |
hint |
Option<String> | Muted line shown last, after a blank line when anything precedes it. |
rows |
Vec<Row> | Count rows in push order. |
success |
Option<SuccessMessage> | Completion message shown after the rows, after a blank line when anything precedes it. |
title |
Option<String> | Heading shown above the rows; not shown when there are no rows. |
Component::new
pub fn new() -> SelfCreate an empty summary with no title, rows, message, or hint.
| Parameter | Type | Description |
|---|---|---|
| returns | Self | A summary that displays as nothing until something is set. |
Component::empty_message
pub fn empty_message(self, message: impl Into<String>) -> SelfSet the message rendered in place of the row block when no rows are pushed.
| Parameter | Type | Description |
|---|---|---|
message |
impl Into<String> | the text for the nothing-to-do case |
| returns | Self | The summary with the empty message set. |
Component::hint
pub fn hint(self, hint: impl Into<String>) -> SelfAppend a trailing hint line rendered with the muted theme.
| Parameter | Type | Description |
|---|---|---|
hint |
impl Into<String> | the hint text; a second call replaces the first |
| returns | Self | The summary with the hint set. |
Component::is_empty
pub fn is_empty(&self) -> boolReport whether any rows have been pushed.
| Parameter | Type | Description |
|---|---|---|
| returns | bool | true when no row has been pushed. |
Component::row
pub fn row(self, label: impl Into<String>, count: usize) -> SelfAppend a row with a label, count, and no detail text.
| Parameter | Type | Description |
|---|---|---|
label |
impl Into<String> | the row name |
count |
usize | the number to show |
| returns | Self | The summary with the row appended. |
Component::row_with_detail
pub fn row_with_detail(
self,
label: impl Into<String>,
count: usize,
detail: Option<impl Into<String>>,
) -> SelfAppend a row with a label, count, and optional parenthesized detail text.
| Parameter | Type | Description |
|---|---|---|
label |
impl Into<String> | the row name |
count |
usize | the number to show |
detail |
Option<impl Into<String>> | the text to show in parentheses; None shows none |
| returns | Self | The summary with the row appended. |
Component::success
pub fn success(self, message: SuccessMessage) -> SelfAttach a completion SuccessMessage rendered beneath the summary block.
| Parameter | Type | Description |
|---|---|---|
message |
SuccessMessage | the completion message |
| returns | Self | The summary with the message set. |
Component::title
pub fn title(self, title: impl Into<String>) -> SelfSet the title rendered above the row block (e.g. Purge summary:).
| Parameter | Type | Description |
|---|---|---|
title |
impl Into<String> | the heading text |
| returns | Self | The summary with the title set. |
struct Row
struct RowA single row in a Component summary.
| Field | Type | Description |
|---|---|---|
count |
usize | Number shown after the label. |
detail |
Option<String> | Text shown in parentheses after the count. |
label |
String | Row name, shown before a colon. |
fn write_row
fn write_row(f: &mut Formatter<'_>, row: &Row) -> fmt::ResultFormat a single row as <label>: <count> with an optional (<detail>) suffix.
| Parameter | Type | Description |
|---|---|---|
f |
&mut Formatter<'_> | the formatter to write to |
row |
&Row | the row to write |
| returns | fmt::Result | The formatter’s result. |