pub struct CompositePattern {
    pub expr: BeTree<PatternOperator, Pattern>,
}
Expand description

A pattern composing other ones with operators

Fields§

§expr: BeTree<PatternOperator, Pattern>

Implementations§

Examples found in repository?
src/pattern/pattern.rs (line 91)
32
33
34
35
36
37
38
39
40
41
42
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    pub fn new(
        raw_expr: &BeTree<PatternOperator, PatternParts>,
        search_modes: &SearchModeMap,
        content_search_max_file_size: usize,
    ) -> Result<Self, PatternError> {
        let expr: BeTree<PatternOperator, Pattern> = raw_expr
            .try_map_atoms::<_, PatternError, _>(|pattern_parts| {
                let core = pattern_parts.core();
                Ok(
                    if core.is_empty() {
                        Pattern::None
                    } else {
                        let parts_mode = pattern_parts.mode();
                        let mode = search_modes.search_mode(parts_mode)?;
                        let flags = pattern_parts.flags();
                        match mode {
                            SearchMode::NameExact => Self::NameExact(
                                ExactPattern::from(core)
                            ),
                            SearchMode::NameFuzzy => Self::NameFuzzy(
                                FuzzyPattern::from(core)
                            ),
                            SearchMode::NameRegex => Self::NameRegex(
                                RegexPattern::from(core, flags.unwrap_or(""))?
                            ),
                            SearchMode::NameTokens => Self::NameTokens(
                                TokPattern::new(core)
                            ),
                            SearchMode::PathExact => Self::PathExact(
                                ExactPattern::from(core)
                            ),
                            SearchMode::PathFuzzy => Self::PathFuzzy(
                                FuzzyPattern::from(core)
                            ),
                            SearchMode::PathRegex => Self::PathRegex(
                                RegexPattern::from(core, flags.unwrap_or(""))?
                            ),
                            SearchMode::PathTokens => Self::PathTokens(
                                TokPattern::new(core)
                            ),
                            SearchMode::ContentExact => Self::ContentExact(
                                ContentExactPattern::new(core, content_search_max_file_size)
                            ),
                            SearchMode::ContentRegex => Self::ContentRegex(
                                ContentRegexPattern::new(
                                    core,
                                    flags.unwrap_or(""),
                                    content_search_max_file_size,
                                )?
                            ),
                        }
                    }
                )
            })?;
        Ok(if expr.is_empty() {
            Pattern::None
        } else if expr.is_atomic() {
            expr.atoms().pop().unwrap()
        } else {
            Self::Composite(CompositePattern::new(expr))
        })
    }
Examples found in repository?
src/pattern/pattern.rs (line 188)
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    pub fn score_of_string(&self, candidate: &str) -> Option<i32> {
        match self {
            Self::NameExact(ep) => ep.score_of(candidate),
            Self::NameFuzzy(fp) => fp.score_of(candidate),
            Self::NameRegex(rp) => rp.find(candidate).map(|m| m.score),
            Self::NameTokens(tp) => tp.score_of(candidate),
            Self::PathExact(ep) => ep.score_of(candidate),
            Self::PathFuzzy(fp) => fp.score_of(candidate),
            Self::PathRegex(rp) => rp.find(candidate).map(|m| m.score),
            Self::PathTokens(tp) => tp.score_of(candidate),
            Self::ContentExact(_) => None, // this isn't suitable
            Self::ContentRegex(_) => None, // this isn't suitable
            Self::Composite(cp) => cp.score_of_string(candidate),
            Self::None => Some(1),
        }
    }
Examples found in repository?
src/pattern/pattern.rs (line 171)
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
    pub fn score_of(&self, candidate: Candidate) -> Option<i32> {
        match self {
            Self::NameExact(ep) => ep.score_of(candidate.name),
            Self::NameFuzzy(fp) => fp.score_of(candidate.name),
            Self::NameRegex(rp) => rp.find(candidate.name).map(|m| m.score),
            Self::NameTokens(tp) => tp.score_of(candidate.name),
            Self::PathExact(ep) => ep.score_of(candidate.subpath),
            Self::PathFuzzy(fp) => fp.score_of(candidate.subpath),
            Self::PathRegex(rp) => rp.find(candidate.subpath).map(|m| m.score),
            Self::PathTokens(tp) => tp.score_of(candidate.subpath),
            Self::ContentExact(cp) => cp.score_of(candidate),
            Self::ContentRegex(cp) => cp.score_of(candidate),
            Self::Composite(cp) => cp.score_of(candidate),
            Self::None => Some(1),
        }
    }
Examples found in repository?
src/pattern/pattern.rs (line 126)
117
118
119
120
121
122
123
124
125
126
127
128
129
    pub fn search_string(
        &self,
        candidate: &str,
    ) -> Option<NameMatch> {
        match self {
            Self::NameExact(ep) | Self::PathExact(ep) => ep.find(candidate),
            Self::NameFuzzy(fp) | Self::PathFuzzy(fp) => fp.find(candidate),
            Self::NameRegex(rp) | Self::PathRegex(rp) => rp.find(candidate),
            Self::NameTokens(tp) | Self::PathTokens(tp) => tp.find(candidate),
            Self::Composite(cp) => cp.search_string(candidate),
            _ => None,
        }
    }
Examples found in repository?
src/pattern/pattern.rs (line 141)
133
134
135
136
137
138
139
140
141
142
143
144
    pub fn search_content(
        &self,
        candidate: &Path,
        desired_len: usize, // available space for content match display
    ) -> Option<ContentMatch> {
        match self {
            Self::ContentExact(cp) => cp.get_content_match(candidate, desired_len),
            Self::ContentRegex(cp) => cp.get_content_match(candidate, desired_len),
            Self::Composite(cp) => cp.search_content(candidate, desired_len),
            _ => None,
        }
    }
Examples found in repository?
src/pattern/pattern.rs (line 154)
147
148
149
150
151
152
153
154
155
156
157
    pub fn get_match_line_count(
        &self,
        path: &Path,
    ) -> Option<usize> {
        match self {
            Self::ContentExact(cp) => cp.get_match_line_count(path),
            Self::ContentRegex(cp) => cp.get_match_line_count(path),
            Self::Composite(cp) => cp.get_match_line_count(path),
            _ => None,
        }
    }
Examples found in repository?
src/pattern/pattern.rs (line 219)
215
216
217
218
219
220
221
222
    pub fn has_real_scores(&self) -> bool {
        match self {
            Self::NameExact(_) | Self::NameFuzzy(_) => true,
            Self::PathExact(_) | Self::PathFuzzy(_) => true,
            Self::Composite(cp) => cp.has_real_scores(),
            _ => false,
        }
    }
Examples found in repository?
src/pattern/pattern.rs (line 207)
199
200
201
202
203
204
205
206
207
208
209
210
    pub fn is_empty(&self) -> bool {
        match self {
            Self::NameExact(ep) | Self::PathExact(ep) => ep.is_empty(),
            Self::ContentExact(ep) => ep.is_empty(),
            Self::NameFuzzy(fp) | Self::PathFuzzy(fp) => fp.is_empty(),
            Self::NameRegex(rp) | Self::PathRegex(rp) => rp.is_empty(),
            Self::ContentRegex(rp) => rp.is_empty(),
            Self::NameTokens(tp) | Self::PathTokens(tp) => tp.is_empty(),
            Self::Composite(cp) => cp.is_empty(),
            Self::None => true,
        }
    }

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.