pub struct PathFilter { /* private fields */ }Expand description
A sophisticated path filter that supports multiple matching strategies.
The filter uses an OR logic - a path is included if it matches ANY of the configured criteria. This allows for flexible and powerful filtering configurations.
§Examples
// Create a filter that matches encoder paths or any weight path
let filter = PathFilter::new()
.with_regex(r"^encoder\..*")
.with_regex(r".*\.weight$")
.with_full_path("special_tensor");
// Check if a path should be included
if filter.matches("encoder.layer1.weight") {
// This will match due to both regex patterns
}Implementations§
Source§impl PathFilter
impl PathFilter
Sourcepub fn with_regex<S: AsRef<str>>(self, pattern: S) -> Self
pub fn with_regex<S: AsRef<str>>(self, pattern: S) -> Self
Add a regex pattern for matching paths
Sourcepub fn with_regexes<I, S>(self, patterns: I) -> Self
pub fn with_regexes<I, S>(self, patterns: I) -> Self
Add multiple regex patterns
Sourcepub fn with_full_path<S: Into<String>>(self, path: S) -> Self
pub fn with_full_path<S: Into<String>>(self, path: S) -> Self
Add an exact full path to match
Sourcepub fn with_full_paths<I, S>(self, paths: I) -> Self
pub fn with_full_paths<I, S>(self, paths: I) -> Self
Add multiple exact full paths
Sourcepub fn with_predicate(self, predicate: fn(&str, &str) -> bool) -> Self
pub fn with_predicate(self, predicate: fn(&str, &str) -> bool) -> Self
Add a predicate function for custom matching based on path and container path
Sourcepub fn with_predicates<I>(self, predicates: I) -> Self
pub fn with_predicates<I>(self, predicates: I) -> Self
Add multiple predicates
Sourcepub fn matches(&self, path: &str) -> bool
pub fn matches(&self, path: &str) -> bool
Check if a path matches this filter (assumes empty container path for backward compatibility)
Sourcepub fn matches_with_container(&self, path: &str, container_type: &str) -> bool
pub fn matches_with_container(&self, path: &str, container_type: &str) -> bool
Check if a path and container type match this filter (for backward compatibility)
Sourcepub fn matches_with_container_path(
&self,
path: &[String],
container_stack: &[String],
) -> bool
pub fn matches_with_container_path( &self, path: &[String], container_stack: &[String], ) -> bool
Check if a path and container path match this filter
Sourcepub fn matches_with_container_path_str(
&self,
path: &str,
container_path: &str,
) -> bool
pub fn matches_with_container_path_str( &self, path: &str, container_path: &str, ) -> bool
Check if a path and container path (dot-notated strings) match this filter
Sourcepub fn criteria_count(&self) -> usize
pub fn criteria_count(&self) -> usize
Get the number of filter criteria configured
Sourcepub fn clear_regex(&mut self) -> &mut Self
pub fn clear_regex(&mut self) -> &mut Self
Clear all regex patterns
Sourcepub fn clear_paths(&mut self) -> &mut Self
pub fn clear_paths(&mut self) -> &mut Self
Clear all exact paths
Sourcepub fn clear_predicates(&mut self) -> &mut Self
pub fn clear_predicates(&mut self) -> &mut Self
Clear all predicates
Sourcepub fn from_regex_patterns<I, S>(patterns: I) -> Self
pub fn from_regex_patterns<I, S>(patterns: I) -> Self
Create a filter from regex patterns only
Sourcepub fn from_paths<I, S>(paths: I) -> Self
pub fn from_paths<I, S>(paths: I) -> Self
Create a filter from exact paths only
Trait Implementations§
Source§impl Clone for PathFilter
impl Clone for PathFilter
Source§fn clone(&self) -> PathFilter
fn clone(&self) -> PathFilter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more