Find

Struct Find 

Source
pub struct Find<'a> { /* private fields */ }
Expand description

File finder with pattern matching support.

Create via Find::new() and chain methods to configure the search.

§Examples

§Basic Pattern Matching

use heroforge_core::Repository;
use heroforge_core::fs::Find;

let repo = Repository::open("project.forge")?;

// Find all Rust source files
let rust_files = Find::new(&repo)
    .pattern("**/*.rs")
    .paths()?;

// Find multiple patterns
let source_files = Find::new(&repo)
    .patterns(&["**/*.rs", "**/*.toml", "**/*.md"])
    .paths()?;

§Ignore Patterns

// Exclude build artifacts
let files = Find::new(&repo)
    .pattern("**/*.rs")
    .ignore("target/**")
    .ignore("**/generated/**")
    .paths()?;

// Use common gitignore patterns
let clean = Find::new(&repo)
    .pattern("**/*")
    .use_gitignore()
    .ignore_hidden()
    .paths()?;

§Directory and Depth Limits

// Search only in src directory
let src_files = Find::new(&repo)
    .in_dir("src")
    .pattern("**/*.rs")
    .paths()?;

// Limit depth to 2 levels
let shallow = Find::new(&repo)
    .pattern("**/*")
    .max_depth(2)
    .paths()?;

Implementations§

Source§

impl<'a> Find<'a>

Source

pub fn new(repo: &'a Repository) -> Self

Create a new Find instance for the given repository.

Source

pub fn at_commit(self, hash: &str) -> Self

Search at a specific commit hash.

Source

pub fn on_trunk(self) -> Self

Search on trunk (default).

Source

pub fn on_branch(self, branch: &str) -> Result<Self>

Search on a specific branch.

Source

pub fn pattern(self, pattern: &str) -> Self

Add a glob pattern to match files.

Supports standard glob syntax:

  • * matches any sequence of characters in a path segment
  • ** matches any sequence of path segments
  • ? matches any single character
  • [abc] matches any character in the brackets
Source

pub fn patterns(self, patterns: &[&str]) -> Self

Add multiple glob patterns at once.

Source

pub fn ignore(self, pattern: &str) -> Self

Exclude files matching this pattern.

Source

pub fn ignore_patterns(self, patterns: &[&str]) -> Self

Add multiple ignore patterns at once.

Source

pub fn ignore_hidden(self) -> Self

Exclude hidden files (files starting with .).

Source

pub fn use_gitignore(self) -> Self

Apply common gitignore-style patterns.

Source

pub fn ignore_case(self) -> Self

Enable case-insensitive pattern matching.

Source

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

Limit search to a maximum directory depth.

Source

pub fn files_only(self) -> Self

Only match regular files (exclude executables and symlinks).

Source

pub fn executables_only(self) -> Self

Only match executable files.

Only match symbolic links.

Source

pub fn min_size(self, bytes: usize) -> Self

Filter to files at least this size (in bytes).

Source

pub fn max_size(self, bytes: usize) -> Self

Filter to files at most this size (in bytes).

Source

pub fn in_dir(self, dir: &str) -> Self

Restrict search to a specific directory.

Source

pub fn execute(&self) -> Result<FindResult>

Execute the search and return full results with metadata.

Source

pub fn paths(&self) -> Result<Vec<String>>

Execute and return just the file paths.

Source

pub fn count(&self) -> Result<usize>

Execute and return only the count of matching files.

Auto Trait Implementations§

§

impl<'a> Freeze for Find<'a>

§

impl<'a> !RefUnwindSafe for Find<'a>

§

impl<'a> !Send for Find<'a>

§

impl<'a> !Sync for Find<'a>

§

impl<'a> Unpin for Find<'a>

§

impl<'a> !UnwindSafe for Find<'a>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.