diff options
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | appveyor.yml | 1 | ||||
-rw-r--r-- | examples/csv.rs | 7 | ||||
-rw-r--r-- | 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=
@@ -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() {} @@ -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<W: Write>(&self, w: W) -> csv::Result<csv::Writer<W>> {
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<W: Write>(&self, mut writer: csv::Writer<W>) -> csv::Result<csv::Writer<W>> {
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<Table> {
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<P: AsRef<Path>>(csv_p: P) -> csv::Result<Table> {
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<R: Read>(reader: &mut csv::Reader<R>) -> 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<W: Write>(&self, w: W) -> csv::Result<csv::Writer<W>> {
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<W: Write>(&self, writer: csv::Writer<W>) -> csv::Result<csv::Writer<W>> {
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;
|