Struct fsort::file_collection::DynamicCollection
[−]
[src]
pub struct DynamicCollection { /* fields omitted */ }
A sorted collection of files with changeable criterion.
Methods
impl DynamicCollection
[src]
fn new<T: Criterion + 'static>() -> DynamicCollection
Creates a new sorted collection with a specific criterion.
Examples
use fsort::criterion::FileName; use fsort::file_collection::DynamicCollection; let collection = DynamicCollection::new::<FileName>();
fn set_criterion<T: Criterion + 'static>(&mut self)
Changes the sorting criterion.
Examples
use std::fs::File; use std::path::PathBuf; use fsort::criterion::{FileName, FileSize}; use fsort::file_collection::{FileCollection, DynamicCollection}; // Creates 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); 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()); 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());
Trait Implementations
impl FileCollection for DynamicCollection
[src]
fn add_file(&mut self, path: &Path) -> Result
Adds a file to the collection. # Examples See DynamicCollection::set_criterion
Read more
fn add_directory(
&mut self,
path: &Path,
recursive: bool,
error_behavior: ErrorBehavior
) -> Result
&mut self,
path: &Path,
recursive: bool,
error_behavior: ErrorBehavior
) -> Result
Adds all files of a directory to the collection.
fn set_order(&mut self, order: Order)
Sets the current order of the collection.
fn get_order(&self) -> Order
Returns the current order of the collection.
fn path_iter(&self) -> PathIter
Returns an iterator about all the (sorted) paths in the collection according to the order. # Examples See DynamicCollection::set_criterion
Read more