Struct Column

Source
pub struct Column<'src> { /* private fields */ }
Expand description

A column in a table.

Implementations§

Source§

impl<'src> Column<'src>

Source

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§

Source§

impl<'src> Clone for Column<'src>

Source§

fn clone(&self) -> Column<'src>

Returns a copy 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<'src> Debug for Column<'src>

Source§

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

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

impl<'src> Default for Column<'src>

Source§

fn default() -> Self

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

impl<'src> PartialEq for Column<'src>

Source§

fn eq(&self, other: &Column<'src>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'src> Eq for Column<'src>

Source§

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> 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, 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.