6 releases (3 breaking)
0.4.0 | Nov 23, 2023 |
---|---|
0.3.0 | Jan 10, 2023 |
0.2.1 | Jan 2, 2022 |
0.2.0 | Dec 25, 2021 |
0.1.0 | Nov 30, 2021 |
#755 in Filesystem
41 downloads per month
Used in zsplit-cli
20KB
194 lines
zsplit
Split text into multiple files by line.
This is the library and not the CLI application. It is called zsplit-cli
.
Examples
Simple
use zsplit::prelude::*;
let data = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9";
let mut source = std::io::BufReader::new(data.as_bytes());
let mut destinations = vec![
Destination::buffer(), // first_destination
Destination::buffer(), // second_destination
Destination::buffer(), // third_destination
];
split_round_robin(&mut source, &mut destinations).unwrap();
let third_destination = destinations.pop().unwrap();
let second_destination = destinations.pop().unwrap();
let first_destination = destinations.pop().unwrap();
assert_eq!(first_destination.into_utf8_string().unwrap(), "0\n3\n6\n9");
assert_eq!(second_destination.into_utf8_string().unwrap(), "1\n4\n7\n");
assert_eq!(third_destination.into_utf8_string().unwrap(), "2\n5\n8\n");
Unsymmetric Distribution
use zsplit::prelude::*;
let data = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9";
let mut source = std::io::BufReader::new(data.as_bytes());
let mut destinations = vec![
Destination::buffer_with_lines(3), // first_destination
Destination::buffer_with_lines(3), // second_destination
Destination::buffer(), // third_destination
];
split_round_robin(&mut source, &mut destinations).unwrap();
let third_destination = destinations.pop().unwrap();
let second_destination = destinations.pop().unwrap();
let first_destination = destinations.pop().unwrap();
assert_eq!(first_destination.into_utf8_string().unwrap(), "0\n1\n2\n7\n8\n9\n");
assert_eq!(second_destination.into_utf8_string().unwrap(), "3\n4\n5\n");
assert_eq!(third_destination.into_utf8_string().unwrap(), "6\n");
CREV - Rust code reviews - Raise awareness
Please, spread this info !
Open source code needs a community effort to express trustworthiness.
Start with reading the reviews of the crates you use. Example: web.crev.dev/rust-reviews/crate/num-traits/
Than install the CLI cargo-crev. Read the Getting Started guide.
On your Rust project, verify the trustworthiness of all dependencies, including transient dependencies with cargo crev verify
Write a new review !
Describe the crates you trust. Or warn about the crate versions you think are dangerous.
Help other developers, inform them and share your opinion.
Use the helper on this webpage: web.crev.dev/rust-reviews/review_new