Crates.io | fsort |
lib.rs | fsort |
version | 1.0.0 |
source | src |
created_at | 2016-07-27 13:59:35.021388 |
updated_at | 2016-07-27 13:59:35.021388 |
description | fsort is a crate to sort files in a fast, OS-independent and 'rusty' way. |
homepage | https://github.com/Christopher22/fsort.git |
repository | https://github.com/Christopher22/fsort.git |
max_upload_size | |
id | 5797 |
size | 29,324 |
fsort is a crate to sort files in a fast, OS-independent and 'rusty' way.
use std::fs::File;
use std::path::PathBuf;
use fsort::criterion::{FileName, FileSize};
use fsort::file_collection::{FileCollection, DynamicCollection};
fn main() {
// Create temporal files
let mut s1 = std::env::temp_dir();
let mut s2 = std::env::temp_dir();
s1.push("S1.tmp");
s2.push("S2.tmp");
File::create(&s1).unwrap().set_len(10);
File::create(&s2).unwrap().set_len(5);
// Inserts files into collection
let mut collection = DynamicCollection::new::<FileName>();
collection.add_file(&s2);
collection.add_file(&s1);
// Sort files by name and iterate over the paths
let mut iter_name = collection.path_iter();
assert_eq!(s1, iter_name.next().unwrap());
assert_eq!(s2, iter_name.next().unwrap());
assert_eq!(None, iter_name.next());
// Change sort criterion and iterate again
collection.set_criterion::<FileSize>();
let mut iter_size = collection.path_iter();
assert_eq!(s2, iter_size.next().unwrap());
assert_eq!(s1, iter_size.next().unwrap());
assert_eq!(None, iter_size.next());
}
##Author Christopher Gundler (c.gundler@mail.de)
##License Licensed under either of
##Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.