PathFilter

Struct PathFilter 

Source
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

Source

pub fn new() -> Self

Create a new empty filter (matches nothing by default)

Source

pub fn all() -> Self

Create a filter that matches all paths

Source

pub fn none() -> Self

Create a filter that matches nothing

Source

pub fn with_regex<S: AsRef<str>>(self, pattern: S) -> Self

Add a regex pattern for matching paths

Source

pub fn with_regexes<I, S>(self, patterns: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Add multiple regex patterns

Source

pub fn with_full_path<S: Into<String>>(self, path: S) -> Self

Add an exact full path to match

Source

pub fn with_full_paths<I, S>(self, paths: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple exact full paths

Source

pub fn with_predicate(self, predicate: fn(&str, &str) -> bool) -> Self

Add a predicate function for custom matching based on path and container path

Source

pub fn with_predicates<I>(self, predicates: I) -> Self
where I: IntoIterator<Item = fn(&str, &str) -> bool>,

Add multiple predicates

Source

pub fn match_all(self) -> Self

Set to match all paths

Source

pub fn matches(&self, path: &str) -> bool

Check if a path matches this filter (assumes empty container path for backward compatibility)

Source

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)

Source

pub fn matches_with_container_path( &self, path: &[String], container_stack: &[String], ) -> bool

Check if a path and container path match this filter

Source

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

Source

pub fn is_empty(&self) -> bool

Check if the filter is empty (matches nothing)

Source

pub fn criteria_count(&self) -> usize

Get the number of filter criteria configured

Source

pub fn clear_regex(&mut self) -> &mut Self

Clear all regex patterns

Source

pub fn clear_paths(&mut self) -> &mut Self

Clear all exact paths

Source

pub fn clear_predicates(&mut self) -> &mut Self

Clear all predicates

Source

pub fn clear(&mut self) -> &mut Self

Clear all filters

Source

pub fn from_regex_patterns<I, S>(patterns: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Create a filter from regex patterns only

Source

pub fn from_paths<I, S>(paths: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Create a filter from exact paths only

Source

pub fn from_predicate(predicate: fn(&str, &str) -> bool) -> Self

Create a filter from a single predicate

Source

pub fn or(self, other: Self) -> Self

Combine with another filter using OR logic

Trait Implementations§

Source§

impl Clone for PathFilter

Source§

fn clone(&self) -> PathFilter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PathFilter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PathFilter

Source§

fn default() -> PathFilter

Returns the “default value” for a type. Read more
Source§

impl Display for PathFilter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V