pub struct Needle { /* private fields */ }
Expand description

a strict (non fuzzy, case sensitive) pattern which may be searched in file contents

Implementations§

Examples found in repository?
src/pattern/content_pattern.rs (line 28)
27
28
29
    pub fn new(pat: &str, max_file_size: usize) -> Self {
        Self { needle: Needle::new(pat, max_file_size) }
    }
Examples found in repository?
src/pattern/content_pattern.rs (line 36)
35
36
37
    pub fn is_empty(&self) -> bool {
        self.needle.is_empty()
    }
Examples found in repository?
src/pattern/content_pattern.rs (line 32)
31
32
33
    pub fn as_str(&self) -> &str {
        self.needle.as_str()
    }
More examples
Hide additional examples
src/content_search/needle.rs (line 222)
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
    pub fn get_match<P: AsRef<Path>>(
        &self,
        hay_path: P,
        desired_len: usize,
    ) -> Option<ContentMatch> {
        let hay = match get_mmap(hay_path) {
            Ok(hay) => hay,
            _ => { return None; }
        };
        match self.search_mmap(&hay) {
            ContentSearchResult::Found { pos } => {
                Some(ContentMatch::build(&hay, pos, self.as_str(), desired_len))
            }
            _ => None,
        }
    }

determine whether the file contains the needle

Examples found in repository?
src/pattern/content_pattern.rs (line 47)
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    pub fn score_of(&self, candidate: Candidate) -> Option<i32> {
        if !candidate.regular_file {
            return None;
        }
        match self.needle.search(candidate.path) {
            Ok(ContentSearchResult::Found { .. }) => Some(1),
            Ok(ContentSearchResult::NotFound) => None,
            Ok(ContentSearchResult::NotSuitable) => {
                None
            }
            Err(e) => {
                debug!("error while scanning {:?} : {:?}", &candidate.path, e);
                None
            }
        }
    }

    /// get the line of the first match, if any
    pub fn get_match_line_count(
        &self,
        path: &Path,
    ) -> Option<usize> {
        if let Ok(ContentSearchResult::Found { pos }) = self.needle.search(path) {
            line_count_at_pos(path, pos).ok()
        } else {
            None
        }
    }

this is supposed to be called only when it’s known that there’s a match

Examples found in repository?
src/pattern/content_pattern.rs (line 77)
72
73
74
75
76
77
78
    pub fn get_content_match(
        &self,
        path: &Path,
        desired_len: usize,
    ) -> Option<ContentMatch> {
        self.needle.get_match(path, desired_len)
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.