pub struct Column<'src> { /* private fields */ }
Expand description
A column in a table.
Implementations§
Source§impl<'src> Column<'src>
impl<'src> Column<'src>
Sourcepub const fn new(
title: Option<(&'src str, ColumnAlign)>,
size: ColumnSize,
align: ColumnAlign,
padding: usize,
) -> Self
pub const fn new( title: Option<(&'src str, ColumnAlign)>, size: ColumnSize, align: ColumnAlign, padding: usize, ) -> Self
Create a new Column using all data.
Examples found in repository?
examples/custom.rs (line 16)
5pub fn main() {
6 // Import these two fields for brevity in the following section.
7 use ColumnAlign::*;
8 use ColumnSize::*;
9
10 let formatter = TableFormatter::new([
11 // Column 1 will use the default settings. These are used by tuples.
12 Column::default(),
13 // This is the same as column 1, but written more explicitly.
14 // It has no title, will fit the data in its column, is left-aligned,
15 // and has a padding of 1 space
16 Column::new(None, Contain, Left, 1),
17 // Similar to column 2, but has a title.
18 // This column will grow to accomodate its data, but only up to 7
19 // characters— data will be split with newlines if needed.
20 //
21 // Because this column has a title, all columns without titles in
22 // this graph will get a blank title when printed.
23 Column::new(Some(("Fruit", Left)), ContainMax(5), Left, 1),
24 // This column has a fixed width of 32, and has 5 spaces
25 // of padding around the data, which is centered. Note that the
26 // actual width of this column will be 42 (32 + 5 + 5) due
27 // to the padding.
28 Column::new(None, Fixed(12), Centered, 5),
29 // You should be able to tell how this one will look by this point.
30 Column::new(Some(("Data", Centered)), Fixed(8), Right, 1),
31 ]);
32
33 // The above formatter has 5 columns specified, so any data we put in
34 // must turn into a [String; 5] with DebugTableRow— this is true
35 // for length-5 tuples.
36 let data = [
37 (1, 'H', "Apple", true, 2.3),
38 (2, 'E', "Pineapple", false, 5.5),
39 (3, 'L', "Kiwi", false, 11.5),
40 (4, 'L', "Banana", true, 0.5),
41 (5, 'O', "Strawberry", false, 0.25)
42 ];
43
44 // Print data just as normal.
45 let _ = formatter.debug_print(data);
46}
Trait Implementations§
impl<'src> Eq for Column<'src>
impl<'src> StructuralPartialEq for Column<'src>
Auto Trait Implementations§
impl<'src> Freeze for Column<'src>
impl<'src> RefUnwindSafe for Column<'src>
impl<'src> Send for Column<'src>
impl<'src> Sync for Column<'src>
impl<'src> Unpin for Column<'src>
impl<'src> UnwindSafe for Column<'src>
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