Skip to content

Commit

Permalink
1.0.0-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed May 25, 2017
1 parent 9d68a92 commit 6a84124
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "csv"
version = "1.0.0-beta.2" #:version
version = "1.0.0-beta.3" #:version
authors = ["Andrew Gallant <[email protected]>"]
description = "Fast CSV parsing with support for serde."
documentation = "http:https://burntsushi.net/rustdoc/csv/"
Expand All @@ -19,7 +19,7 @@ appveyor = { repository = "BurntSushi/rust-csv" }
bench = false

[dependencies]
csv-core = { path = "csv-core", version = "0.1.0" }
csv-core = { path = "csv-core", version = "0.1.2" }
serde = "1.0.7"

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
csv = "1.0.0-beta.2"
csv = "1.0.0-beta.3"
```

and this to your crate root:
Expand All @@ -35,7 +35,7 @@ This example shows how to read CSV data from stdin and print each record to
stdout.

There are more examples in the
[cookbook](https://docs.rs/csv/1.0.0-beta.2/csv/examples/index.html).
[cookbook](https://docs.rs/csv/1.0.0-beta.3/csv/examples/index.html).

```rust
extern crate csv;
Expand Down
2 changes: 1 addition & 1 deletion csv-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "csv-core"
version = "0.1.1" #:version
version = "0.1.2" #:version
authors = ["Andrew Gallant <[email protected]>"]
description = "Bare bones CSV parsing with no_std support."
documentation = "https://docs.rs/csv-core"
Expand Down
6 changes: 3 additions & 3 deletions csv-index/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "csv-index"
version = "0.1.1" #:version
version = "0.1.2" #:version
authors = ["Andrew Gallant <[email protected]>"]
description = "On disk CSV indexing data structures."
documentation = "https://docs.rs/csv-index"
Expand All @@ -20,8 +20,8 @@ bench = false

[dependencies]
byteorder = "1"
csv = { path = "..", version = "1.0.0-beta.2" }
csv-core = { path = "../csv-core", version = "0.1.1" }
csv = { path = "..", version = "1.0.0-beta.3" }
csv-core = { path = "../csv-core", version = "0.1.2" }

[profile.release]
debug = true
Expand Down
89 changes: 86 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Add this to your `Cargo.toml`:
```toml
[dependencies]
csv = "1.0.0-beta.2"
csv = "1.0.0-beta.3"
```
and this to your crate root:
Expand Down Expand Up @@ -178,12 +178,13 @@ extern crate serde_derive;

use std::result;

pub use csv_core::{QuoteStyle, Terminator};
use serde::{Deserialize, Deserializer};

pub use byte_record::{ByteRecord, ByteRecordIter, Position};
pub use deserializer::{DeserializeError, DeserializeErrorKind};
pub use error::{Error, FromUtf8Error, IntoInnerError, Result, Utf8Error};
pub use error::{
Error, ErrorKind, FromUtf8Error, IntoInnerError, Result, Utf8Error,
};
pub use reader::{
Reader, ReaderBuilder,
DeserializeRecordsIntoIter, DeserializeRecordsIter,
Expand All @@ -203,6 +204,88 @@ mod string_record;
pub mod tutorial;
mod writer;

/// The quoting style to use when writing CSV data.
#[derive(Clone, Copy, Debug)]
pub enum QuoteStyle {
/// This puts quotes around every field. Always.
Always,
/// This puts quotes around fields only when necessary.
///
/// They are necessary when fields contain a quote, delimiter or record
/// terminator. Quotes are also necessary when writing an empty record
/// (which is indistinguishable from a record with one empty field).
///
/// This is the default.
Necessary,
/// This puts quotes around all fields that are non-numeric. Namely, when
/// writing a field that does not parse as a valid float or integer, then
/// quotes will be used even if they aren't strictly necessary.
NonNumeric,
/// This *never* writes quotes, even if it would produce invalid CSV data.
Never,
/// Hints that destructuring should not be exhaustive.
///
/// This enum may grow additional variants, so this makes sure clients
/// don't count on exhaustive matching. (Otherwise, adding a new variant
/// could break existing code.)
#[doc(hidden)]
__Nonexhaustive,
}

impl QuoteStyle {
fn to_core(self) -> csv_core::QuoteStyle {
match self {
QuoteStyle::Always => csv_core::QuoteStyle::Always,
QuoteStyle::Necessary => csv_core::QuoteStyle::Necessary,
QuoteStyle::NonNumeric => csv_core::QuoteStyle::NonNumeric,
QuoteStyle::Never => csv_core::QuoteStyle::Never,
_ => unreachable!(),
}
}
}

impl Default for QuoteStyle {
fn default() -> QuoteStyle {
QuoteStyle::Necessary
}
}

/// A record terminator.
///
/// Use this to specify the record terminator while parsing CSV. The default is
/// CRLF, which treats `\r`, `\n` or `\r\n` as a single record terminator.
#[derive(Clone, Copy, Debug)]
pub enum Terminator {
/// Parses `\r`, `\n` or `\r\n` as a single record terminator.
CRLF,
/// Parses the byte given as a record terminator.
Any(u8),
/// Hints that destructuring should not be exhaustive.
///
/// This enum may grow additional variants, so this makes sure clients
/// don't count on exhaustive matching. (Otherwise, adding a new variant
/// could break existing code.)
#[doc(hidden)]
__Nonexhaustive,
}

impl Terminator {
/// Convert this to the csv_core type of the same name.
fn to_core(self) -> csv_core::Terminator {
match self {
Terminator::CRLF => csv_core::Terminator::CRLF,
Terminator::Any(b) => csv_core::Terminator::Any(b),
_ => unreachable!(),
}
}
}

impl Default for Terminator {
fn default() -> Terminator {
Terminator::CRLF
}
}

/// A custom Serde deserializer for possibly invalid `Option<T>` fields.
///
/// When deserializing CSV data, it is sometimes desirable to simply ignore
Expand Down
6 changes: 3 additions & 3 deletions src/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $ cd csvtutor
```
Once inside `csvtutor`, open `Cargo.toml` in your favorite text editor and add
`csv = "1.0.0-beta.2"` to your `[dependencies]` section. At this point, your
`csv = "1.0.0-beta.3"` to your `[dependencies]` section. At this point, your
`Cargo.toml` should look something like this:
```text
Expand All @@ -63,7 +63,7 @@ version = "0.1.0"
authors = ["Your Name"]
[dependencies]
csv = "1.0.0-beta.2"
csv = "1.0.0-beta.3"
```
Next, let's build your project. Since you added the `csv` crate as a
Expand Down Expand Up @@ -478,7 +478,7 @@ StringRecord(["Oakman", "AL", "", "33.7133333", "-87.3886111"])
This example contains two new pieces of code:
1. Code for querying the positional arguments of your program. We put this code
into its own funcation called `get_first_arg`. Our program expects a file
into its own function called `get_first_arg`. Our program expects a file
path in the first position (which is indexed at `1`; the argument at index
`0` is the executable name), so if one doesn't exist, then `get_first_arg`
returns an error.
Expand Down

0 comments on commit 6a84124

Please sign in to comment.