From 33b8187c30eaed9d6d7d3a71a2b315d3e3577c0e Mon Sep 17 00:00:00 2001 From: Alexander Bulaev Date: Sat, 17 Sep 2016 23:09:16 +0300 Subject: cfg-out `csv` feature It pulls `rustc-serialize` which is not always desirable --- .travis.yml | 5 +++++ Cargo.toml | 6 +++--- appveyor.yml | 1 + examples/csv.rs | 7 ++++++- src/lib.rs | 14 +++++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78e6502..c2d90f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,11 @@ rust: - stable - beta - nightly +script: +- cargo build --verbose +- cargo test --verbose +- cargo build --verbose --no-default-features +- cargo test --verbose --no-default-features env: global: - secure: k+5s8j7arJSoqS/7BnX7vBEXb1csFsn/cr+WCxRQtlV7bK8JkQ/3t3E1MCUpCSHJLb6K+GlRSkN6tWkhPVUpYA57J7+bSADJ2cAWBq2ArMubXMkMl/t7ibuOArGggDRLulYZ83kDZEkVcMs3QyAv7cGvSMnj6VehTeUrZsIreHmNGJnpsxuXqsfaHhiToWkO/KTRGHOuro7xQczCKzV54g7NAfIgWvcy3T5zVpkaNZWGd/BaRvkBRP8fZpqNBQSlG3Unq3q6wWIeLIJd3QWAQCrzDDMNIbiwsU/KHOJfVvvDFDJF/rzn1EwVvkWRQmT+GtPmLDCRV5OD4hmjVyEtdFU1aLaxxeQBNdSUb3SsDbnUkfyX+WgHEAYRxRAOGW8vhA7+9gaMI2fStkc5JwAcfrZxKkDd9YsUX4iYNk207zsRz/5M6gTWCw2e7jLj9kUGMiTy+008TRxAjSNbN9sl+FRMH5BPMDlgDM4Ohp1+JRq0Mfu1qT6hoYXb+AoRvHijw9HoqtaU2lTamuSN6+LFNJ0CDt2Qhy4jn+Dmp5ZlivcUVzpQpdZoPG00BnLK6YfYoCF9gFX194TM2T6ljhYGaL7ITZI9Cz4qMxD3r459aGz8sUAcTkSbTRMGpTb4fJVfvCgsP2IDfKO7WS/W4SbCzYMh7PfpQg03BAvld0y69O8= diff --git a/Cargo.toml b/Cargo.toml index 2d2b194..3a96ee7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "prettytable-rs" -version = "0.6.4" +version = "0.6.5" description = "A library for printing pretty formatted tables in terminal" homepage = "https://github.com/phsym/prettytable-rs" repository = "https://github.com/phsym/prettytable-rs" @@ -12,7 +12,7 @@ keywords = ["tab", "table", "format", "pretty", "print"] license = "BSD-3-Clause" [features] -default = ["win_crlf"] +default = ["win_crlf", "csv"] win_crlf = [] [[bin]] @@ -27,4 +27,4 @@ term = "^0.4" lazy_static = "^0.2" atty = "^0.2" encode_unicode = "^0.2" -csv = "^0.14" +csv = { version = "^0.14", optional = true } diff --git a/appveyor.yml b/appveyor.yml index 90cdbae..c9bcc00 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,3 +10,4 @@ build_script: test_script: - cargo test --verbose + - cargo test --verbose --no-default-features diff --git a/examples/csv.rs b/examples/csv.rs index df14173..f9202e7 100644 --- a/examples/csv.rs +++ b/examples/csv.rs @@ -1,5 +1,4 @@ extern crate prettytable; -use prettytable::Table; /* Following main function will print : @@ -15,7 +14,10 @@ use prettytable::Table; foobar,bar,foo foobar2,bar2,foo2 */ +#[cfg(feature = "csv")] fn main() { + use prettytable::Table; + let table = Table::from_csv_string("ABC,DEFG,HIJKLMN\n\ foobar,bar,foo\n\ foobar2,bar2,foo2").unwrap(); @@ -24,3 +26,6 @@ fn main() { println!(""); println!("{}", table.to_csv(Vec::new()).unwrap().into_string()); } + +#[cfg(not(feature = "csv"))] +fn main() {} diff --git a/src/lib.rs b/src/lib.rs index 0d2f756..c0bdeec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,12 +2,16 @@ extern crate unicode_width; extern crate term; extern crate atty; +#[cfg(feature = "csv")] extern crate csv; #[macro_use] extern crate lazy_static; extern crate encode_unicode; -use std::io::{self, Read, Write, Error}; +use std::io::{self, Write, Error}; +#[cfg(feature = "csv")] +use std::io::Read; use std::fmt; +#[cfg(feature = "csv")] use std::path::Path; use std::iter::{FromIterator, IntoIterator}; use std::slice::{Iter, IterMut}; @@ -182,6 +186,7 @@ impl <'a> TableSlice<'a> { } /// Write the table to the specified writer. + #[cfg(feature = "csv")] pub fn to_csv(&self, w: W) -> csv::Result> { self.to_csv_writer(csv::Writer::from_writer(w)) } @@ -189,6 +194,7 @@ impl <'a> TableSlice<'a> { /// Write the table to the specified writer. /// /// This allows for format customisation. + #[cfg(feature = "csv")] pub fn to_csv_writer(&self, mut writer: csv::Writer) -> csv::Result> { for title in self.titles { try!(writer.write(title.iter().map(|c| c.get_content()))); @@ -228,6 +234,7 @@ impl Table { /// Create a table from a CSV string /// /// For more customisability use `from_csv()` + #[cfg(feature = "csv")] pub fn from_csv_string(csv_s: &str) -> csv::Result { Ok(Table::from_csv(&mut csv::Reader::from_string(csv_s).has_headers(false))) } @@ -235,11 +242,13 @@ impl Table { /// Create a table from a CSV file /// /// For more customisability use `from_csv()` + #[cfg(feature = "csv")] pub fn from_csv_file>(csv_p: P) -> csv::Result
{ Ok(Table::from_csv(&mut try!(csv::Reader::from_file(csv_p)).has_headers(false))) } /// Create a table from a CSV reader + #[cfg(feature = "csv")] pub fn from_csv(reader: &mut csv::Reader) -> Table { Table::init(reader.records().map(|row| Row::new(row.unwrap().into_iter().map(|cell| Cell::new(&cell)).collect())).collect()) } @@ -371,6 +380,7 @@ impl Table { } /// Write the table to the specified writer. + #[cfg(feature = "csv")] pub fn to_csv(&self, w: W) -> csv::Result> { self.as_ref().to_csv(w) } @@ -378,6 +388,7 @@ impl Table { /// Write the table to the specified writer. /// /// This allows for format customisation. + #[cfg(feature = "csv")] pub fn to_csv_writer(&self, writer: csv::Writer) -> csv::Result> { self.as_ref().to_csv_writer(writer) } @@ -739,6 +750,7 @@ mod tests { assert_eq!(out, table.to_string().replace("\r\n", "\n")); } + #[cfg(feature = "csv")] mod csv { use Table; use row::Row; -- cgit v1.2.3