summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpierresy <phsym@msn.com>2016-01-03 12:02:10 +0100
committerpierresy <phsym@msn.com>2016-01-03 12:02:10 +0100
commitaac360ceac297ed09e1f036381a9ebe9e4ab709d (patch)
treec829da6610c2fad108b7adbd52c5a71033deb9fb
parent5a8df3a0d256aa6f48da0b7c185640e49bf38501 (diff)
Added an example file using table slicing for #10
-rw-r--r--examples/slices.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/slices.rs b/examples/slices.rs
new file mode 100644
index 0000000..c1d5d98
--- /dev/null
+++ b/examples/slices.rs
@@ -0,0 +1,28 @@
+#[macro_use] extern crate prettytable;
+
+use prettytable::Slice;
+
+fn main() {
+ let mut table = table![[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]];
+ table.set_titles(row![cell!("t1"), cell!("t2"), cell!("t3")]);
+
+ let slice = table.slice(..);
+ let slice = slice.slice(2..);
+ let slice = slice.slice(..3);
+
+ /*
+ Will print
+ +----+----+----+
+ | t1 | t2 | t3 |
+ +====+====+====+
+ | 2 | 2 | 2 |
+ +----+----+----+
+ | 3 | 3 | 3 |
+ +----+----+----+
+ */
+ slice.printstd();
+
+ // This is equivalent to
+ let slice = table.slice(2..3);
+ slice.printstd();
+}