Closed mucks closed 1 year ago
Hey @mucks , that's awesome... will look into it soon
Hey @mucks, thank you for contributing, i like your code. What do you think to make it like this
use std::time::SystemTime;
use rust_search::{filter::*, SearchBuilder};
let search: Vec<String> = SearchBuilder::default()
.filter(created_before(SystemTime::now()))
.filter(modified_before(SystemTime::now()))
.filter(file_size_greater(mb(20.0)))
.build()
.collect();
println!("{:?}", search);
Also i think filter
should rename to filters
Note:
We can make the filters to return a function that expects a String
ref: rust-PG
Hey @mucks, thank you for contributing, i like your code. What do you think to make it like this
use std::time::SystemTime; use rust_search::{filter::*, SearchBuilder}; let search: Vec<String> = SearchBuilder::default() .filter(created_before(SystemTime::now())) .filter(modified_before(SystemTime::now())) .filter(file_size_greater(mb(20.0))) .build() .collect(); println!("{:?}", search);
Also i think
filter
should rename tofilters
Note: We can make the filters to return a function that expects a
String
ref: rust-PG
Hi @TheAwiteb, thank you for your feedback! I like your solution and I thought of a way to make the use of filters even more ergonomic in my opinion. I've added a trait called FilterExt that allows you to use the filter functions directly on top of the builder. Here's the example from the README:
use rust_search::{FileSize, FilterExt, SearchBuilder};
use std::time::{Duration, SystemTime};
let search: Vec<String> = SearchBuilder::default()
.location("~/path/to/directory")
.file_size_greater(FileSize::Kilobyte(200.0))
.file_size_smaller(FileSize::Megabyte(10.0))
.created_after(SystemTime::now() - Duration::from_secs(3600 * 24 * 10))
.created_before(SystemTime::now())
.modified_after(SystemTime::now() - Duration::from_secs(3600 * 24 * 5))
.custom_filter(|dir| dir.metadata().unwrap().is_file())
.custom_filter(|dir| !dir.metadata().unwrap().permissions().readonly())
.build()
.collect();
Hey @ParthJadhav can you review it, and also link it with #3
Hi, I've just implemented a way to filter by date_created, date_modified and file_size, there are possibly even more filters since I've exposed the DirEntry directly so it can be used to filter via a closure. The filters are a vec so you can add an arbitrary amount of filters. I'm aware that my solution might not be the best and I'm open to any questions and/or feedback.