A variety of reasons including the fact that this library does not require any external code to perform its task.
Some of the features are as follows: - Serderef. 1 free serializationref. 2 - easy to use API - general, flexible output format
Add this line to your Cargo.toml
:
toml
rustsv = "0.1.5"
You can read the full documentation here.
```rust use rustsv::prelude::*;
// Create our input data let input: String = "surname,initial,address,phone number\ Smith,A,\"14 Made up Drive, Made up City, Ohio\",216-235-3744\ Doe,J,\"15 Fake Street, Phonyville, Texas\",210-214-5737".to_string();
// Parse the input
into Content
// The parameters are as follows:
// 1. Input: String - The text you wish to parse
// 2. Delimiter: Char - The character to delimit by
// 3. Headers: Bool - If the parser should use the first row in the file as headers
let content: Content = parse(input, ',', true);
```
```rust use rustsv::prelude::*;
// Parse the input
into Content
// The parameters are as follows:
// 1. Path: String - The path to the file you wish to parse
// 2. Delimiter: Char - The character to delimit by
// 3. Headers: Bool - If the parser should use the first row in the file as headers
let content: Content = read("./path/to/file.csv", ',', true)?;
```
This method requires the
http
feature to be enabled ref 3 ```rust use rustsv::prelude::*;
// Parse the content of URL
into Content
// The parameters are as follows:
// 1. URL: String - The URL of the file wish to parse
// 2. Delimiter: Char - The character to delimit by
// 3. Headers: Bool - If the parser should use the first row in the file as headers
let content: Content = fetch("https://domain.tld/path/to/file.csv", ',', true)?;
```
Content
:The Content
structure is incredibly flexible, you can use it as an Iterator
, or as an Index
such as an Array.
Iterator
:```rust let content: Content = read("./path/to/file.csv", ',', true);
for entry in content { //do stuff } ```
Index
:```rust let content: Content = read("./path/to/file.csv", ',', true);
let first_row: Entry = content[0]; ```
Entry
?The Entry
structure is the container housing the individual pieces of data from each row in your input, it works similarly to it's Content
parent.
Iterator
:```rust let content: Content = read("./path/to/file.csv", ',', true);
let first_row: Entry = content[0];
for keypair in firstrow { println!("Key: {}, Value: {}", keypair.0, keypair.1); } ```
Index
:```rust let content: Content = read("./path/to/file.csv", ',', true);
let first_row: Entry = content[0];
let entryname: String = firstrow["name"]; ``` Now, I know what you are thinking "well that is not very rusty", dont worry for all of you die-hard rusty api users, I have an update coming soon for you, but for now im taking it slow and introducing this API first.
Well, I have already got some ideas of what I want to provide in the next minor release of this library, and so I will be working very heavily on that for now.
For now, the only way I would like contributions is through GitHub issues, as these are the easiest for me to track, however that does not rule out the possibilty of PRs, thus, you are welcome to help as much as you want, however I am much slower at responding to PRs than Issues.
Well, if you found a bug, or you want to request a feature, the best place to report these bugs and suggest these features is with a Github Issue.
Serde is a serialization and deserialization utility, providing the groundwork for almost all of the (de)serialization libraries out there, I am planning to integrate Serde compatibility into RSV in the next big update
This simply means that you are not required to use Serde to serialize your data, a flaw that most of the other CSV libraries seem to share
http
featureTo enable the HTTP feature of RSV, modify your dependency for RustSV to look like this:
toml
rustsv = { version = "0.1.5", features = ["http"] }