Skip to content

Commit 7461ed0

Browse files
authored
Merge pull request phsym#39 from alexbool/master
cfg-out `csv` feature
2 parents a32f0d2 + 33b8187 commit 7461ed0

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ rust:
33
- stable
44
- beta
55
- nightly
6+
script:
7+
- cargo build --verbose
8+
- cargo test --verbose
9+
- cargo build --verbose --no-default-features
10+
- cargo test --verbose --no-default-features
611
env:
712
global:
813
- 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=

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "prettytable-rs"
4-
version = "0.6.4"
4+
version = "0.6.5"
55
description = "A library for printing pretty formatted tables in terminal"
66
homepage = "https://github.com/phsym/prettytable-rs"
77
repository = "https://github.com/phsym/prettytable-rs"
@@ -12,7 +12,7 @@ keywords = ["tab", "table", "format", "pretty", "print"]
1212
license = "BSD-3-Clause"
1313

1414
[features]
15-
default = ["win_crlf"]
15+
default = ["win_crlf", "csv"]
1616
win_crlf = []
1717

1818
[[bin]]
@@ -27,4 +27,4 @@ term = "^0.4"
2727
lazy_static = "^0.2"
2828
atty = "^0.2"
2929
encode_unicode = "^0.2"
30-
csv = "^0.14"
30+
csv = { version = "^0.14", optional = true }

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ build_script:
1010

1111
test_script:
1212
- cargo test --verbose
13+
- cargo test --verbose --no-default-features

examples/csv.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
extern crate prettytable;
2-
use prettytable::Table;
32

43
/*
54
Following main function will print :
@@ -15,7 +14,10 @@ use prettytable::Table;
1514
foobar,bar,foo
1615
foobar2,bar2,foo2
1716
*/
17+
#[cfg(feature = "csv")]
1818
fn main() {
19+
use prettytable::Table;
20+
1921
let table = Table::from_csv_string("ABC,DEFG,HIJKLMN\n\
2022
foobar,bar,foo\n\
2123
foobar2,bar2,foo2").unwrap();
@@ -24,3 +26,6 @@ fn main() {
2426
println!("");
2527
println!("{}", table.to_csv(Vec::new()).unwrap().into_string());
2628
}
29+
30+
#[cfg(not(feature = "csv"))]
31+
fn main() {}

src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
extern crate unicode_width;
33
extern crate term;
44
extern crate atty;
5+
#[cfg(feature = "csv")]
56
extern crate csv;
67
#[macro_use] extern crate lazy_static;
78
extern crate encode_unicode;
89

9-
use std::io::{self, Read, Write, Error};
10+
use std::io::{self, Write, Error};
11+
#[cfg(feature = "csv")]
12+
use std::io::Read;
1013
use std::fmt;
14+
#[cfg(feature = "csv")]
1115
use std::path::Path;
1216
use std::iter::{FromIterator, IntoIterator};
1317
use std::slice::{Iter, IterMut};
@@ -182,13 +186,15 @@ impl <'a> TableSlice<'a> {
182186
}
183187

184188
/// Write the table to the specified writer.
189+
#[cfg(feature = "csv")]
185190
pub fn to_csv<W: Write>(&self, w: W) -> csv::Result<csv::Writer<W>> {
186191
self.to_csv_writer(csv::Writer::from_writer(w))
187192
}
188193

189194
/// Write the table to the specified writer.
190195
///
191196
/// This allows for format customisation.
197+
#[cfg(feature = "csv")]
192198
pub fn to_csv_writer<W: Write>(&self, mut writer: csv::Writer<W>) -> csv::Result<csv::Writer<W>> {
193199
for title in self.titles {
194200
try!(writer.write(title.iter().map(|c| c.get_content())));
@@ -228,18 +234,21 @@ impl Table {
228234
/// Create a table from a CSV string
229235
///
230236
/// For more customisability use `from_csv()`
237+
#[cfg(feature = "csv")]
231238
pub fn from_csv_string(csv_s: &str) -> csv::Result<Table> {
232239
Ok(Table::from_csv(&mut csv::Reader::from_string(csv_s).has_headers(false)))
233240
}
234241

235242
/// Create a table from a CSV file
236243
///
237244
/// For more customisability use `from_csv()`
245+
#[cfg(feature = "csv")]
238246
pub fn from_csv_file<P: AsRef<Path>>(csv_p: P) -> csv::Result<Table> {
239247
Ok(Table::from_csv(&mut try!(csv::Reader::from_file(csv_p)).has_headers(false)))
240248
}
241249

242250
/// Create a table from a CSV reader
251+
#[cfg(feature = "csv")]
243252
pub fn from_csv<R: Read>(reader: &mut csv::Reader<R>) -> Table {
244253
Table::init(reader.records().map(|row| Row::new(row.unwrap().into_iter().map(|cell| Cell::new(&cell)).collect())).collect())
245254
}
@@ -371,13 +380,15 @@ impl Table {
371380
}
372381

373382
/// Write the table to the specified writer.
383+
#[cfg(feature = "csv")]
374384
pub fn to_csv<W: Write>(&self, w: W) -> csv::Result<csv::Writer<W>> {
375385
self.as_ref().to_csv(w)
376386
}
377387

378388
/// Write the table to the specified writer.
379389
///
380390
/// This allows for format customisation.
391+
#[cfg(feature = "csv")]
381392
pub fn to_csv_writer<W: Write>(&self, writer: csv::Writer<W>) -> csv::Result<csv::Writer<W>> {
382393
self.as_ref().to_csv_writer(writer)
383394
}
@@ -739,6 +750,7 @@ mod tests {
739750
assert_eq!(out, table.to_string().replace("\r\n", "\n"));
740751
}
741752

753+
#[cfg(feature = "csv")]
742754
mod csv {
743755
use Table;
744756
use row::Row;

0 commit comments

Comments
 (0)