1 个稳定版本
使用旧的 Rust 2015
1.0.0 | 2016年7月27日 |
---|
#1757 在 数据结构
30KB
587 行
fsort 
fsort 是一个用于快速、操作系统无关和 'rusty' 方式排序文件的 crate。
功能
- 简单排序
- 许多标准:名称、大小、创建日期、访问日期、...
- 纯 Rust 实现,无依赖
- 操作系统无关
示例
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());
}
##作者 Christopher Gundler ([email protected])
##许可证 许可证为
- Apache 许可证第 2 版 (https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (http://opensource.org/licenses/MIT),任选其一。
##贡献 除非你明确声明,否则任何有意提交以包含在本作品中的贡献,根据 Apache-2.0 许可证定义,应按上述方式双许可,不附加任何额外条款或条件。