Struct PreTable

Source
pub struct PreTable { /* private fields */ }
Expand description

A PreTable struct used for table representation

Implementations§

Source§

impl PreTable

Source

pub fn new() -> Self

Creates a new instance of PreTable

Examples found in repository?
examples/example/main.rs (line 6)
5fn main() {
6    let mut table = PreTable::new();
7
8    table.set_header_with_alignment(vec![
9        ("NAME", Alignment::Left),
10        ("FORMAL", Alignment::Center),
11        ("HEIGHT", Alignment::Right),
12    ]);
13
14    table.add_body(vec!["Everest", "Chomolungma", "8848m"]);
15    table.add_body(vec!["K2", "Karakorum No.2", "8611m"]);
16    table.add_body(vec!["Kanchenjunga", "", "8505m"]);
17
18    println!("{}", table.output());
19}
More examples
Hide additional examples
examples/large_case.rs (line 10)
5pub fn main() {
6    let n = 1_000_000;
7
8    let numbers = (0..n).map(|i| (i + 1).to_string()).collect::<Vec<_>>();
9
10    let mut table = PreTable::new();
11    table.set_header(vec!["i"]);
12    for n in numbers.iter() {
13        table.add_body(vec![n]);
14    }
15
16    let output = table.output();
17
18    // 処理が削除されないように output を使うフリをする。
19    let t = output.as_bytes();
20    println!("{}", t[3] + t[t.len() - 3]);
21}
Source

pub fn add_header(&mut self, v: &str)

Adds a header to the table with default alignment

Source

pub fn add_header_with_alignment(&mut self, v: &str, alignment: Alignment)

Adds a header with a specified alignment

§Examples
let mut table = PreTable::new();
table.add_header_with_alignment("KEY", Alignment::Left);
Source

pub fn set_header(&mut self, v: Vec<&str>)

Sets the headers of the table with default alignment

§Examples
let mut table = PreTable::new();
table.set_header(vec!["KEY", "VALUE", "DESCRIPTION"]);
Examples found in repository?
examples/large_case.rs (line 11)
5pub fn main() {
6    let n = 1_000_000;
7
8    let numbers = (0..n).map(|i| (i + 1).to_string()).collect::<Vec<_>>();
9
10    let mut table = PreTable::new();
11    table.set_header(vec!["i"]);
12    for n in numbers.iter() {
13        table.add_body(vec![n]);
14    }
15
16    let output = table.output();
17
18    // 処理が削除されないように output を使うフリをする。
19    let t = output.as_bytes();
20    println!("{}", t[3] + t[t.len() - 3]);
21}
Source

pub fn set_header_with_alignment(&mut self, v: Vec<(&str, Alignment)>)

Sets the headers of the table with a specified alignment

§Examples
let mut table = PreTable::new();
table.set_header_with_alignment(vec![
    ("KEY", Alignment::Left),
    ("VALUE", Alignment::Center),
    ("DESCRIPTION", Alignment::Right),
]);
Examples found in repository?
examples/example/main.rs (lines 8-12)
5fn main() {
6    let mut table = PreTable::new();
7
8    table.set_header_with_alignment(vec![
9        ("NAME", Alignment::Left),
10        ("FORMAL", Alignment::Center),
11        ("HEIGHT", Alignment::Right),
12    ]);
13
14    table.add_body(vec!["Everest", "Chomolungma", "8848m"]);
15    table.add_body(vec!["K2", "Karakorum No.2", "8611m"]);
16    table.add_body(vec!["Kanchenjunga", "", "8505m"]);
17
18    println!("{}", table.output());
19}
Source

pub fn add_body(&mut self, v: Vec<&str>)

Adds a row to the body of the table

§Examples
let mut table = PreTable::new();
table.set_header(vec!["KEY", "VALUE", "DESCRIPTION"]);
table.add_body(vec!["key1", "value1", "description1"]);
Examples found in repository?
examples/example/main.rs (line 14)
5fn main() {
6    let mut table = PreTable::new();
7
8    table.set_header_with_alignment(vec![
9        ("NAME", Alignment::Left),
10        ("FORMAL", Alignment::Center),
11        ("HEIGHT", Alignment::Right),
12    ]);
13
14    table.add_body(vec!["Everest", "Chomolungma", "8848m"]);
15    table.add_body(vec!["K2", "Karakorum No.2", "8611m"]);
16    table.add_body(vec!["Kanchenjunga", "", "8505m"]);
17
18    println!("{}", table.output());
19}
More examples
Hide additional examples
examples/large_case.rs (line 13)
5pub fn main() {
6    let n = 1_000_000;
7
8    let numbers = (0..n).map(|i| (i + 1).to_string()).collect::<Vec<_>>();
9
10    let mut table = PreTable::new();
11    table.set_header(vec!["i"]);
12    for n in numbers.iter() {
13        table.add_body(vec![n]);
14    }
15
16    let output = table.output();
17
18    // 処理が削除されないように output を使うフリをする。
19    let t = output.as_bytes();
20    println!("{}", t[3] + t[t.len() - 3]);
21}
Source

pub fn line(&self) -> String

Generates a line string based on the current state of table

Source

pub fn output(&self) -> String

Returns the complete table as a string

Examples found in repository?
examples/example/main.rs (line 18)
5fn main() {
6    let mut table = PreTable::new();
7
8    table.set_header_with_alignment(vec![
9        ("NAME", Alignment::Left),
10        ("FORMAL", Alignment::Center),
11        ("HEIGHT", Alignment::Right),
12    ]);
13
14    table.add_body(vec!["Everest", "Chomolungma", "8848m"]);
15    table.add_body(vec!["K2", "Karakorum No.2", "8611m"]);
16    table.add_body(vec!["Kanchenjunga", "", "8505m"]);
17
18    println!("{}", table.output());
19}
More examples
Hide additional examples
examples/large_case.rs (line 16)
5pub fn main() {
6    let n = 1_000_000;
7
8    let numbers = (0..n).map(|i| (i + 1).to_string()).collect::<Vec<_>>();
9
10    let mut table = PreTable::new();
11    table.set_header(vec!["i"]);
12    for n in numbers.iter() {
13        table.add_body(vec![n]);
14    }
15
16    let output = table.output();
17
18    // 処理が削除されないように output を使うフリをする。
19    let t = output.as_bytes();
20    println!("{}", t[3] + t[t.len() - 3]);
21}
Source

pub fn set_show_header(&mut self, b: bool)

Decides whether to show the header in output

Source

pub fn set_body_split(&mut self, b: bool)

Decides whether to split the body in output

Source

pub fn set_line_char(&mut self, c: char)

Sets the character used for line separation

Source

pub fn set_vertical_char(&mut self, c: char)

Sets the character used for vertical separation

Source

pub fn set_corner_char(&mut self, c: char)

Sets the character used for corners

Source

pub fn set_default_alignment(&mut self, a: Alignment)

Sets the alignment used for format align

Trait Implementations§

Source§

impl Debug for PreTable

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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