| Crates.io | parse_list |
| lib.rs | parse_list |
| version | 2.0.0 |
| created_at | 2019-09-27 05:44:38.158103+00 |
| updated_at | 2019-09-27 07:00:11.608794+00 |
| description | Parse files and lists of stringified things into lists of thingified things |
| homepage | |
| repository | https://github.com/brson/parse_list |
| max_upload_size | |
| id | 168027 |
| size | 13,896 |
Parse files and lists of stringified things into lists of thingified things.
That is, if you've got something Read-y or Iterator-y over u8s,
Strings, or strs, and a type that implements FromStr, you can also
have an Iterator of that type of thing.
Particularly designed to parse files of newline-separated things, like these git integers:
0
1
2
3
4
Load your ints with ease:
// Create the file of test data
use std::fs;
let tmp_dir = TempDir::new("tmp").unwrap();
let file_path = tmp_dir.path().join("list");
fs::write(&file_path, "0\n1\n2\n3\n4").unwrap();
// Load from file. Note that each element could result in an individual
// I/O or parse error. Here those are converted into a single `Result<Vec<u32>, _>`.
let v = from_file_lines(&file_path);
let v: Vec<Result<u32, _>> = v.unwrap().collect();
let v: Result<Vec<u32>, _> = v.into_iter().collect();
let v = v.unwrap();
assert!(v == vec![0, 1, 2, 3, 4]);
This work is distributed under the super-Rust quad-license:
Apache-2.0/MIT/BSL-1.0/CC0-1.0
This is equivalent to public domain in jurisdictions that allow it (CC0-1.0). Otherwise it is compatible with the Rust license, plus the option of the runtime-exception-containing BSL-1. This means that, outside of public domain jurisdictions, the source must be distributed along with author attribution and at least one of the licenses; but in binary form no attribution or license distribution is required.