Crates.io | rustsv |
lib.rs | rustsv |
version | 0.1.5 |
source | src |
created_at | 2020-10-19 22:58:17.235426 |
updated_at | 2020-10-21 15:23:45.320493 |
description | A customizable CSV data parser |
homepage | |
repository | https://github.com/fatalcenturion/RSV |
max_upload_size | |
id | 303175 |
size | 26,294 |
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:
Add this line to your Cargo.toml
:
rustsv = "0.1.5"
You can read the full documentation here.
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);
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
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
:let content: Content = read("./path/to/file.csv", ',', true);
for entry in content {
//do stuff
}
Index
: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
:let content: Content = read("./path/to/file.csv", ',', true);
let first_row: Entry = content[0];
for key_pair in first_row {
println!("Key: {}, Value: {}", key_pair.0, key_pair.1);
}
Index
:let content: Content = read("./path/to/file.csv", ',', true);
let first_row: Entry = content[0];
let entry_name: String = first_row["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:
rustsv = { version = "0.1.5", features = ["http"] }