pub struct Row { /* private fields */ }Implementations§
Source§impl Row
impl Row
Sourcepub fn new() -> Self
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}Sourcepub fn with_alignment<I, S>(contents: I, alignment: Alignment) -> Self
pub fn with_alignment<I, S>(contents: I, alignment: Alignment) -> Self
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}Sourcepub fn push(&mut self, cell: Cell)
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}Sourcepub fn remove(&mut self, index: usize) -> Option<Cell>
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.
Sourcepub fn cell_mut(&mut self, index: usize) -> Option<&mut Cell>
pub fn cell_mut(&mut self, index: usize) -> Option<&mut Cell>
Returns a mutable reference to the cell at the specified index.
pub fn cells(&self) -> &[Cell]
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn as_array<const N: usize>(&self) -> Option<&[Cell; N]>
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 cellsNoneif 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§
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> 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
Mutably borrows from an owned value. Read more