SearchBuilder

Struct SearchBuilder 

Source
pub struct SearchBuilder { /* private fields */ }
Expand description

Builder for a Search instance, allowing for more complex searches.

Implementations§

Source§

impl SearchBuilder

Source

pub fn build(&self) -> Search

Build a new Search instance.

Source

pub fn location(self, location: impl AsRef<Path>) -> Self

Set the search location to search in.

§Notes
§Arguments
  • location - The location to search in.
§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .location("src")
    .build()
    .collect();
Source

pub fn search_input(self, input: impl Into<String>) -> Self

Set the search input.

§Arguments
  • input - The search input.
§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .search_input("Search")
    .build()
    .collect();
Source

pub fn ext(self, ext: impl Into<String>) -> Self

Set the file extension to search for.

§Arguments
  • ext - The file extension to search for.
§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .ext("rs")
    .build()
    .collect();
Source

pub fn filter(self, filter: FilterType) -> Self

Add a filter to the search function.

§Arguments
  • filter - Closure getting dir: DirEntry variable to modify
§Examples
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();
Source

pub fn depth(self, depth: usize) -> Self

Set the depth to search to, meaning how many subdirectories to search in.

§Arguments
  • depth - The depth to search to.
§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .depth(1)
    .build()
    .collect();
Source

pub fn limit(self, limit: usize) -> Self

Set the limit of results to return. This will limit the amount of results returned.

§Arguments
  • limit - The limit of results to return.
§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .limit(5)
    .build()
    .collect();
Source

pub fn strict(self) -> Self

Searches for exact match.

For example, if the search input is “Search”, the file “Search.rs” will be found, but not “Searcher.rs”.

§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .search_input("name")
    .strict()
    .build()
    .collect();
Source

pub fn ignore_case(self) -> Self

Set search option to be case insensitive.

For example, if the search input is “Search”, the file “search.rs” will be found.

§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .search_input("name")
    .ignore_case()
    .build()
    .collect();
Source

pub fn hidden(self) -> Self

Searches for hidden files.

§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .with_hidden()
    .build()
    .collect();
Source

pub fn more_locations(self, more_locations: Vec<impl AsRef<Path>>) -> Self

Add extra locations to search in, in addition to the main location.

§Notes
§Arguments
  • more_locations - locations to search in.
§Examples
use rust_search::SearchBuilder;

let search: Vec<String> = SearchBuilder::default()
    .more_locations(vec!["/Users/username/b/", "/Users/username/c/"])
    .build()
    .collect();

Trait Implementations§

Source§

impl Default for SearchBuilder

Source§

fn default() -> Self

With this default, the search will get all files from the current directory.

Source§

impl FilterExt for SearchBuilder

Source§

fn created_before(self, t: SystemTime) -> Self

files created before t: SystemTime
Source§

fn created_at(self, t: SystemTime) -> Self

files created at t: SystemTime
Source§

fn created_after(self, t: SystemTime) -> Self

files created after t: SystemTime
Source§

fn modified_before(self, t: SystemTime) -> Self

files created before t: SystemTime
Source§

fn modified_at(self, t: SystemTime) -> Self

files modified at t: SystemTime
Source§

fn modified_after(self, t: SystemTime) -> Self

files modified after t: SystemTime
Source§

fn file_size_smaller(self, size: FileSize) -> Self

files smaller than size_in_bytes: usize
Source§

fn file_size_equal(self, size: FileSize) -> Self

files equal to size_in_bytes: usize
Source§

fn file_size_greater(self, size: FileSize) -> Self

files greater than size_in_bytes: usize
Source§

fn custom_filter(self, f: FilterFn) -> Self

custom filter that exposes the DirEntry directly Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.