summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Silbermayr <wolfgang@silbermayr.at>2018-09-04 11:10:00 +0200
committerWolfgang Silbermayr <wolfgang@silbermayr.at>2018-09-04 11:10:00 +0200
commit3d734f731442a3781954903d62a61f2b9c3d686d (patch)
tree7683e11ddb02124e7b13763447e5e656b72a7723
parentece1d8e012eef9782e175f0485b8da2d9ab8b1db (diff)
Update csv to version 1
-rw-r--r--Cargo.toml2
-rw-r--r--examples/csv.rs3
-rw-r--r--src/lib.rs45
3 files changed, 35 insertions, 15 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0af2394..7697053 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -34,4 +34,4 @@ term = "^0.5"
lazy_static = "1"
atty = "^0.2"
encode_unicode = "^0.3"
-csv = { version = "0.15", optional = true }
+csv = { version = "1", optional = true }
diff --git a/examples/csv.rs b/examples/csv.rs
index dd104af..8dbaab1 100644
--- a/examples/csv.rs
+++ b/examples/csv.rs
@@ -25,7 +25,8 @@ fn main() {
table.printstd();
println!("");
- println!("{}", table.to_csv(Vec::new()).unwrap().into_string());
+ println!("{}",
+ String::from_utf8(table.to_csv(Vec::new()).unwrap().into_inner().unwrap()).unwrap());
}
#[cfg(not(feature = "csv"))]
diff --git a/src/lib.rs b/src/lib.rs
index a3adbfe..906f97b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -215,10 +215,10 @@ impl<'a> TableSlice<'a> {
mut writer: csv::Writer<W>)
-> csv::Result<csv::Writer<W>> {
for title in self.titles {
- writer.write(title.iter().map(|c| c.get_content()))?;
+ writer.write_record(title.iter().map(|c| c.get_content()))?;
}
for row in self.rows {
- writer.write(row.iter().map(|c| c.get_content()))?;
+ writer.write_record(row.iter().map(|c| c.get_content()))?;
}
writer.flush()?;
@@ -254,7 +254,10 @@ impl Table {
/// 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)))
+ Ok(Table::from_csv(
+ &mut csv::ReaderBuilder::new()
+ .has_headers(false)
+ .from_reader(csv_s.as_bytes())))
}
/// Create a table from a CSV file
@@ -262,7 +265,10 @@ impl Table {
/// 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 csv::Reader::from_file(csv_p)?.has_headers(false)))
+ Ok(Table::from_csv(
+ &mut csv::ReaderBuilder::new()
+ .has_headers(false)
+ .from_path(csv_p)?))
}
/// Create a table from a CSV reader
@@ -1056,19 +1062,32 @@ mod tests {
#[test]
fn to() {
- assert_eq!(test_table().to_csv(Vec::new()).unwrap().as_string(), CSV_S);
+ assert_eq!(
+ String::from_utf8(
+ test_table()
+ .to_csv(Vec::new())
+ .unwrap()
+ .into_inner()
+ .unwrap()
+ ).unwrap(),
+ CSV_S);
}
#[test]
fn trans() {
- assert_eq!(Table::from_csv_string(test_table()
- .to_csv(Vec::new())
- .unwrap()
- .as_string())
- .unwrap()
- .to_string()
- .replace("\r\n", "\n"),
- test_table().to_string().replace("\r\n", "\n"));
+ assert_eq!(
+ Table::from_csv_string(
+ &String::from_utf8(
+ test_table()
+ .to_csv(Vec::new())
+ .unwrap()
+ .into_inner()
+ .unwrap()
+ ).unwrap()
+ ).unwrap()
+ .to_string()
+ .replace("\r\n", "\n"),
+ test_table().to_string().replace("\r\n", "\n"));
}
#[test]