pub struct PreTable { /* private fields */ }
Expand description
A PreTable
struct used for table representation
Implementations§
Source§impl PreTable
impl PreTable
Sourcepub fn new() -> Self
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
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}
Sourcepub fn add_header(&mut self, v: &str)
pub fn add_header(&mut self, v: &str)
Adds a header to the table with default alignment
Sourcepub fn add_header_with_alignment(&mut self, v: &str, alignment: Alignment)
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);
Sourcepub fn set_header(&mut self, v: Vec<&str>)
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}
Sourcepub fn set_header_with_alignment(&mut self, v: Vec<(&str, Alignment)>)
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}
Sourcepub fn add_body(&mut self, v: Vec<&str>)
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
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}
Sourcepub fn output(&self) -> String
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
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}
Sourcepub fn set_show_header(&mut self, b: bool)
pub fn set_show_header(&mut self, b: bool)
Decides whether to show the header in output
Sourcepub fn set_body_split(&mut self, b: bool)
pub fn set_body_split(&mut self, b: bool)
Decides whether to split the body in output
Sourcepub fn set_line_char(&mut self, c: char)
pub fn set_line_char(&mut self, c: char)
Sets the character used for line separation
Sourcepub fn set_vertical_char(&mut self, c: char)
pub fn set_vertical_char(&mut self, c: char)
Sets the character used for vertical separation
Sourcepub fn set_corner_char(&mut self, c: char)
pub fn set_corner_char(&mut self, c: char)
Sets the character used for corners
Sourcepub fn set_default_alignment(&mut self, a: Alignment)
pub fn set_default_alignment(&mut self, a: Alignment)
Sets the alignment used for format align
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PreTable
impl RefUnwindSafe for PreTable
impl Send for PreTable
impl Sync for PreTable
impl Unpin for PreTable
impl UnwindSafe for PreTable
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