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