pub struct FilterChain { /* private fields */ }Expand description
Filter chain for managing multiple filters
The filter chain manages a collection of filters and automatically handles hardware filter limits by falling back to software filtering.
§Filter Evaluation
Filters are evaluated in order of priority (highest first). A message passes if ANY filter matches (OR logic). An empty chain passes all messages.
§Hardware Filter Management
The chain tracks hardware filter capacity. When the limit is reached, additional filters are automatically treated as software filters.
§Example
use canlink_hal::filter::{FilterChain, IdFilter, RangeFilter};
let mut chain = FilterChain::new(4); // Max 4 hardware filters
chain.add_filter(Box::new(IdFilter::new(0x123)));
chain.add_filter(Box::new(RangeFilter::new(0x200, 0x2FF)));
// Check if a message passes the filter chain
// let passes = chain.matches(&message);Implementations§
Source§impl FilterChain
impl FilterChain
Sourcepub fn new(max_hardware_filters: usize) -> Self
pub fn new(max_hardware_filters: usize) -> Self
Create a new filter chain
§Arguments
max_hardware_filters- Maximum number of hardware filters supported
Sourcepub fn add_filter(&mut self, filter: Box<dyn MessageFilter>)
pub fn add_filter(&mut self, filter: Box<dyn MessageFilter>)
Add a filter to the chain
Filters are added in order. If the filter is a hardware filter and the hardware limit has been reached, it will be treated as a software filter.
§Arguments
filter- The filter to add
Sourcepub fn remove_filter(
&mut self,
index: usize,
) -> Result<Box<dyn MessageFilter>, FilterError>
pub fn remove_filter( &mut self, index: usize, ) -> Result<Box<dyn MessageFilter>, FilterError>
Sourcepub fn matches(&self, message: &CanMessage) -> bool
pub fn matches(&self, message: &CanMessage) -> bool
Check if a message matches any filter in the chain
Returns true if:
- The chain is empty (pass-through mode)
- Any filter in the chain matches the message
Sourcepub fn hardware_filter_count(&self) -> usize
pub fn hardware_filter_count(&self) -> usize
Get the number of hardware filters in use
Sourcepub fn software_filter_count(&self) -> usize
pub fn software_filter_count(&self) -> usize
Get the number of software filters in use
Sourcepub fn max_hardware_filters(&self) -> usize
pub fn max_hardware_filters(&self) -> usize
Get the maximum hardware filter capacity
Sourcepub fn has_hardware_capacity(&self) -> bool
pub fn has_hardware_capacity(&self) -> bool
Check if hardware filter capacity is available
Sourcepub fn total_filter_count(&self) -> usize
pub fn total_filter_count(&self) -> usize
Get the total filter count (alias for len)
Sourcepub fn iter(&self) -> impl Iterator<Item = &dyn MessageFilter>
pub fn iter(&self) -> impl Iterator<Item = &dyn MessageFilter>
Iterate over filters
Source§impl FilterChain
impl FilterChain
Sourcepub fn from_config(config: &FilterConfig) -> Result<Self, FilterError>
pub fn from_config(config: &FilterConfig) -> Result<Self, FilterError>
Create a FilterChain from configuration
§Errors
Returns FilterError if any filter configuration is invalid.