Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs improvement #14

Merged
merged 6 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<div align="center">

![Group 1](https://user-images.githubusercontent.com/42001064/198829818-c4035432-8721-45e1-ba2d-4d2eb6d0c584.svg)

Blazingly fast file search library built in Rust 🔥
Blazingly fast file search crate built in Rust 🔥

[![Version info](https://img.shields.io/crates/v/rust_search.svg)](https://crates.io/crates/rust_search)
[![Documentation](https://docs.rs/rust_search/badge.svg)](https://docs.rs/rust_search)
[![License](https://img.shields.io/crates/l/rust_search.svg)](https://github.com/parthjadhav/rust_search/blob/master/LICENSE-MIT)

</div>

## 📦 Usage

Expand Down Expand Up @@ -74,7 +80,7 @@ The difference in sample size is due to the fact that fd and glob are different
Benchmarks are done using [hyperfine](https://github.com/sharkdp/hyperfine),
Benchmarks files are available in the [benchmarks](https://drive.google.com/drive/folders/1ug6ojNixS5jAe6Lh6M0o2d3tku73zQ9w?usp=sharing) drive folder.

### - Rust vs Glob
### - Rust Search vs Glob

The benchmark was done on a directories containing 300K files.

Expand All @@ -85,7 +91,7 @@ The benchmark was done on a directories containing 300K files.

---

### - Rust vs FD
### - Rust Search vs FD

The benchmark was done on a directories containing 45K files.

Expand All @@ -99,9 +105,9 @@ The benchmark was done on a directories containing 45K files.
### Results:-

```diff
+ Rust_Search is 17.25 times faster than Glob.
+ rust_search is 17.25 times faster than Glob.

+ Rust_Search** is 1.09 times faster than FD.
+ rust_search** is 1.09 times faster than FD.
```
## 👨‍💻 Contributors

Expand Down
67 changes: 36 additions & 31 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::{utils::replace_tilde_with_home_dir, Search};
pub struct SearchBuilder {
/// The location to search in, defaults to the current directory.
search_location: PathBuf,
/// Vector of additional locations to search in.
/// Additional locations to search in.
more_locations: Option<Vec<PathBuf>>,
/// The search input, defaults to search for every word.
/// The search input, default will get all files from locations.
search_input: Option<String>,
/// The file extension to search for, defaults to any file extension.
/// The file extension to search for, defaults to get all extensions.
file_ext: Option<String>,
/// The depth to search to, defaults to no limit.
depth: Option<usize>,
Expand Down Expand Up @@ -48,9 +48,9 @@ impl SearchBuilder {
/// use rust_search::SearchBuilder;
///
/// let search: Vec<String> = SearchBuilder::default()
/// .location("src")
/// .build()
/// .collect();
/// .location("src")
/// .build()
/// .collect();
/// ```
pub fn location(mut self, location: impl AsRef<Path>) -> Self {
self.search_location = replace_tilde_with_home_dir(location);
Expand All @@ -65,9 +65,9 @@ impl SearchBuilder {
/// use rust_search::SearchBuilder;
///
/// let search: Vec<String> = SearchBuilder::default()
/// .search_input("Search")
/// .build()
/// .collect();
/// .search_input("Search")
/// .build()
/// .collect();
/// ```
pub fn search_input(mut self, input: impl Into<String>) -> Self {
self.search_input = Some(input.into());
Expand All @@ -93,83 +93,87 @@ impl SearchBuilder {
self
}

/// Set the depth to search to.
/// Set the depth to search to, meaning how many subdirectories to search in.
/// ### Arguments
/// * `depth` - The depth to search to.
/// ### Examples
/// ```rust
/// use rust_search::SearchBuilder;
///
/// let search: Vec<String> = SearchBuilder::default()
/// .depth(1)
/// .build()
/// .collect();
/// .depth(1)
/// .build()
/// .collect();
/// ```
pub fn depth(mut self, depth: usize) -> Self {
self.depth = Some(depth);
self
}

/// Searches for exact match
/// Searches for exact match.
///
/// For example, if the search input is "Search", the file "Search.rs" will be found, but not "Searcher.rs".
/// ### Examples
/// ```rust
/// use rust_search::SearchBuilder;
///
/// let search: Vec<String> = SearchBuilder::default()
/// .search_input("name")
/// .strict()
/// .build()
/// .collect();
/// .search_input("name")
/// .strict()
/// .build()
/// .collect();
/// ```
pub fn strict(mut self) -> Self {
self.strict = true;
self
}

/// Set search option to be case insensitive.
///
/// For example, if the search input is "Search", the file "search.rs" will be found.
/// ### Examples
/// ```rust
/// use rust_search::SearchBuilder;
///
/// let search: Vec<String> = SearchBuilder::default()
/// .search_input("name")
/// .ignore_case()
/// .build()
/// .collect();
/// .search_input("name")
/// .ignore_case()
/// .build()
/// .collect();
/// ```
pub fn ignore_case(mut self) -> Self {
self.ignore_case = true;
self
}

/// Searches for hidden files
/// Searches for hidden files.
/// ### Examples
/// ```rust
/// use rust_search::SearchBuilder;
///
/// let search: Vec<String> = SearchBuilder::default()
/// .with_hidden()
/// .build()
/// .collect();
/// .with_hidden()
/// .build()
/// .collect();
/// ```
pub fn hidden(mut self) -> Self {
self.hidden = true;
self
}

/// Add extra locations to search in.
/// Add extra locations to search in, in addition to the main location.
/// ## Notes
/// - Will replace `~` with [home directory](https://en.wikipedia.org/wiki/Home_directory)
/// ### Arguments
/// * `more_locations` - Vec<> of locations to search in.
/// * `more_locations` - locations to search in.
/// ### Examples
/// ```rust
/// use rust_search::SearchBuilder;
///
/// let search: Vec<String> = SearchBuilder::default()
/// .more_locations(vec!["/Users/username/b/", "/Users/username/c/"])
/// .build()
/// .collect();
/// .more_locations(vec!["/Users/username/b/", "/Users/username/c/"])
/// .build()
/// .collect();
/// ```
pub fn more_locations(mut self, more_locations: Vec<impl AsRef<Path>>) -> Self {
self.more_locations = Some(
Expand All @@ -183,6 +187,7 @@ impl SearchBuilder {
}

impl Default for SearchBuilder {
/// With this default, the search will get all files from the current directory.
fn default() -> Self {
Self {
search_location: std::env::current_dir().expect("Failed to get current directory"),
Expand Down
3 changes: 3 additions & 0 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ impl Search {
/// * `search_input` - The search input, defaults to any word
/// * `file_ext` - The file extension to search for, defaults to any file extension
/// * `depth` - The depth to search to, defaults to no limit
/// * `strict` - Whether to search for the exact word or not
/// * `ignore_case` - Whether to ignore case or not
/// * `hidden` - Whether to search hidden files or not, files starting with a dot
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
search_location: impl AsRef<Path>,
Expand Down