Skip to main content

Row

Struct Row 

Source
pub struct Row { /* private fields */ }

Implementations§

Source§

impl Row

Source

pub fn new() -> Self

Examples found in repository?
examples/table.rs (line 69)
62fn demo_colspan() {
63    // Colspan example
64    println!("\n=== Colspan Example ===");
65    let mut table = Table::new();
66    table.set_style(TableStyle::Modern);
67
68    // Header row spanning all 5 columns
69    let mut header = Row::new();
70    let mut title_cell = Cell::new("span all 5 columns", Alignment::Left);
71    title_cell.set_span(5);
72    header.push(title_cell);
73    table.set_headers(header);
74
75    // Row: span 4 columns + 1 column
76    let mut row1 = Row::new();
77    let mut span4 = Cell::new("span 4 columns", Alignment::Left);
78    span4.set_span(4);
79    row1.push(span4);
80    row1.push(Cell::new("just 1 column", Alignment::Left));
81    table.add_row(row1);
82
83    // Row: span 3 columns + span 2 columns
84    let mut row2 = Row::new();
85    let mut span3_left = Cell::new("span 3 columns", Alignment::Left);
86    span3_left.set_span(3);
87    row2.push(span3_left);
88    let mut span2_right = Cell::new("span 2 columns", Alignment::Left);
89    span2_right.set_span(2);
90    row2.push(span2_right);
91    table.add_row(row2);
92
93    // Row: span 2 columns + span 3 columns
94    let mut row3 = Row::new();
95    let mut span2_left = Cell::new("span 2 columns", Alignment::Left);
96    span2_left.set_span(2);
97    row3.push(span2_left);
98    let mut span3_right = Cell::new("span 3 columns", Alignment::Left);
99    span3_right.set_span(3);
100    row3.push(span3_right);
101    table.add_row(row3);
102
103    // Row: 1 column + span 4 columns
104    let mut row4 = Row::new();
105    row4.push(Cell::new("just 1 column", Alignment::Left));
106    let mut span4_right = Cell::new("span 4 columns", Alignment::Left);
107    span4_right.set_span(4);
108    row4.push(span4_right);
109    table.add_row(row4);
110
111    // Row: all 5 individual columns
112    table.add_row([
113        "just 1 column",
114        "just 1 column",
115        "just 1 column",
116        "just 1 column",
117        "just 1 column",
118    ]);
119
120    table.print();
121}
122
123fn demo_invoice() {
124    // Invoice style colspan example
125    println!("\n=== Invoice Style with Colspan ===");
126    let mut invoice = Table::new();
127    invoice.set_style(TableStyle::Modern);
128
129    // Invoice header spanning all columns
130    let mut inv_header = Row::new();
131    let mut inv_title = Cell::new("INVOICE #2024-001", Alignment::Center);
132    inv_title.set_span(4);
133    inv_header.push(inv_title);
134    invoice.set_headers(inv_header);
135
136    // Column headers
137    invoice.add_row(Row::with_alignment(
138        ["Item", "Qty", "Price", "Total"],
139        Alignment::Center,
140    ));
141
142    // Line items
143    invoice.add_row(["Widget A", "5", "$10", "$50"]);
144    invoice.add_row(["Widget B", "3", "$15", "$45"]);
145    invoice.add_row(["Service", "1", "$25", "$25"]);
146
147    // Subtotal row
148    let mut subtotal = Row::new();
149    let mut subtotal_label = Cell::new("Subtotal:", Alignment::Right);
150    subtotal_label.set_span(3);
151    subtotal.push(subtotal_label);
152    subtotal.push(Cell::new("$120", Alignment::Right));
153    invoice.add_row(subtotal);
154
155    // Tax row
156    let mut tax = Row::new();
157    let mut tax_label = Cell::new("Tax (10%):", Alignment::Right);
158    tax_label.set_span(3);
159    tax.push(tax_label);
160    tax.push(Cell::new("$12", Alignment::Right));
161    invoice.add_row(tax);
162
163    // Grand total row
164    let mut grand_total = Row::new();
165    let mut total_label = Cell::new("TOTAL:", Alignment::Right);
166    total_label.set_span(3);
167    grand_total.push(total_label);
168    grand_total.push(Cell::new("$132", Alignment::Right));
169    invoice.add_row(grand_total);
170
171    invoice.print();
172}
Source

pub fn with_alignment<I, S>(contents: I, alignment: Alignment) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Examples found in repository?
examples/table.rs (lines 137-140)
123fn demo_invoice() {
124    // Invoice style colspan example
125    println!("\n=== Invoice Style with Colspan ===");
126    let mut invoice = Table::new();
127    invoice.set_style(TableStyle::Modern);
128
129    // Invoice header spanning all columns
130    let mut inv_header = Row::new();
131    let mut inv_title = Cell::new("INVOICE #2024-001", Alignment::Center);
132    inv_title.set_span(4);
133    inv_header.push(inv_title);
134    invoice.set_headers(inv_header);
135
136    // Column headers
137    invoice.add_row(Row::with_alignment(
138        ["Item", "Qty", "Price", "Total"],
139        Alignment::Center,
140    ));
141
142    // Line items
143    invoice.add_row(["Widget A", "5", "$10", "$50"]);
144    invoice.add_row(["Widget B", "3", "$15", "$45"]);
145    invoice.add_row(["Service", "1", "$25", "$25"]);
146
147    // Subtotal row
148    let mut subtotal = Row::new();
149    let mut subtotal_label = Cell::new("Subtotal:", Alignment::Right);
150    subtotal_label.set_span(3);
151    subtotal.push(subtotal_label);
152    subtotal.push(Cell::new("$120", Alignment::Right));
153    invoice.add_row(subtotal);
154
155    // Tax row
156    let mut tax = Row::new();
157    let mut tax_label = Cell::new("Tax (10%):", Alignment::Right);
158    tax_label.set_span(3);
159    tax.push(tax_label);
160    tax.push(Cell::new("$12", Alignment::Right));
161    invoice.add_row(tax);
162
163    // Grand total row
164    let mut grand_total = Row::new();
165    let mut total_label = Cell::new("TOTAL:", Alignment::Right);
166    total_label.set_span(3);
167    grand_total.push(total_label);
168    grand_total.push(Cell::new("$132", Alignment::Right));
169    invoice.add_row(grand_total);
170
171    invoice.print();
172}
Source

pub fn push(&mut self, cell: Cell)

Examples found in repository?
examples/table.rs (line 72)
62fn demo_colspan() {
63    // Colspan example
64    println!("\n=== Colspan Example ===");
65    let mut table = Table::new();
66    table.set_style(TableStyle::Modern);
67
68    // Header row spanning all 5 columns
69    let mut header = Row::new();
70    let mut title_cell = Cell::new("span all 5 columns", Alignment::Left);
71    title_cell.set_span(5);
72    header.push(title_cell);
73    table.set_headers(header);
74
75    // Row: span 4 columns + 1 column
76    let mut row1 = Row::new();
77    let mut span4 = Cell::new("span 4 columns", Alignment::Left);
78    span4.set_span(4);
79    row1.push(span4);
80    row1.push(Cell::new("just 1 column", Alignment::Left));
81    table.add_row(row1);
82
83    // Row: span 3 columns + span 2 columns
84    let mut row2 = Row::new();
85    let mut span3_left = Cell::new("span 3 columns", Alignment::Left);
86    span3_left.set_span(3);
87    row2.push(span3_left);
88    let mut span2_right = Cell::new("span 2 columns", Alignment::Left);
89    span2_right.set_span(2);
90    row2.push(span2_right);
91    table.add_row(row2);
92
93    // Row: span 2 columns + span 3 columns
94    let mut row3 = Row::new();
95    let mut span2_left = Cell::new("span 2 columns", Alignment::Left);
96    span2_left.set_span(2);
97    row3.push(span2_left);
98    let mut span3_right = Cell::new("span 3 columns", Alignment::Left);
99    span3_right.set_span(3);
100    row3.push(span3_right);
101    table.add_row(row3);
102
103    // Row: 1 column + span 4 columns
104    let mut row4 = Row::new();
105    row4.push(Cell::new("just 1 column", Alignment::Left));
106    let mut span4_right = Cell::new("span 4 columns", Alignment::Left);
107    span4_right.set_span(4);
108    row4.push(span4_right);
109    table.add_row(row4);
110
111    // Row: all 5 individual columns
112    table.add_row([
113        "just 1 column",
114        "just 1 column",
115        "just 1 column",
116        "just 1 column",
117        "just 1 column",
118    ]);
119
120    table.print();
121}
122
123fn demo_invoice() {
124    // Invoice style colspan example
125    println!("\n=== Invoice Style with Colspan ===");
126    let mut invoice = Table::new();
127    invoice.set_style(TableStyle::Modern);
128
129    // Invoice header spanning all columns
130    let mut inv_header = Row::new();
131    let mut inv_title = Cell::new("INVOICE #2024-001", Alignment::Center);
132    inv_title.set_span(4);
133    inv_header.push(inv_title);
134    invoice.set_headers(inv_header);
135
136    // Column headers
137    invoice.add_row(Row::with_alignment(
138        ["Item", "Qty", "Price", "Total"],
139        Alignment::Center,
140    ));
141
142    // Line items
143    invoice.add_row(["Widget A", "5", "$10", "$50"]);
144    invoice.add_row(["Widget B", "3", "$15", "$45"]);
145    invoice.add_row(["Service", "1", "$25", "$25"]);
146
147    // Subtotal row
148    let mut subtotal = Row::new();
149    let mut subtotal_label = Cell::new("Subtotal:", Alignment::Right);
150    subtotal_label.set_span(3);
151    subtotal.push(subtotal_label);
152    subtotal.push(Cell::new("$120", Alignment::Right));
153    invoice.add_row(subtotal);
154
155    // Tax row
156    let mut tax = Row::new();
157    let mut tax_label = Cell::new("Tax (10%):", Alignment::Right);
158    tax_label.set_span(3);
159    tax.push(tax_label);
160    tax.push(Cell::new("$12", Alignment::Right));
161    invoice.add_row(tax);
162
163    // Grand total row
164    let mut grand_total = Row::new();
165    let mut total_label = Cell::new("TOTAL:", Alignment::Right);
166    total_label.set_span(3);
167    grand_total.push(total_label);
168    grand_total.push(Cell::new("$132", Alignment::Right));
169    invoice.add_row(grand_total);
170
171    invoice.print();
172}
Source

pub fn insert(&mut self, index: usize, cell: Cell)

Inserts a cell at the specified index.

§Panics

Panics if index > self.len().

Source

pub fn remove(&mut self, index: usize) -> Option<Cell>

Removes and returns the cell at the specified index. Returns None if index is out of bounds.

Source

pub fn cell_mut(&mut self, index: usize) -> Option<&mut Cell>

Returns a mutable reference to the cell at the specified index.

Source

pub fn cells(&self) -> &[Cell]

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_array<const N: usize>(&self) -> Option<&[Cell; N]>

Attempts to convert the row’s cells into a fixed-size array.

This method provides zero-overhead access to rows with a known number of columns, eliminating bounds checking in hot paths.

§Arguments
  • N - The expected number of columns in the row
§Returns
  • Some(&[Cell; N]) if the row has exactly N cells
  • None if the row has a different number of cells
§Examples
use crabular::{Alignment, Row};

let row = Row::with_alignment(&["a", "b", "c"], Alignment::Left);
if let Some(array) = row.as_array::<3>() {
    // Stack-allocated, no bounds checking needed
    assert_eq!(array[0].content(), "a");
}

Trait Implementations§

Source§

impl Clone for Row

Source§

fn clone(&self) -> Row

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Row

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Row

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: AsRef<str>> From<&[S]> for Row

Source§

fn from(contents: &[S]) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<str>, const N: usize> From<&[S; N]> for Row

Source§

fn from(contents: &[S; N]) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<str>, const N: usize> From<[S; N]> for Row

Source§

fn from(contents: [S; N]) -> Self

Converts to this type from the input type.
Source§

impl<S: AsRef<str>> From<Vec<S>> for Row

Source§

fn from(contents: Vec<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Row

§

impl RefUnwindSafe for Row

§

impl Send for Row

§

impl Sync for Row

§

impl Unpin for Row

§

impl UnwindSafe for Row

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.