Skip to main content

FilterChain

Struct FilterChain 

Source
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

Source

pub fn new(max_hardware_filters: usize) -> Self

Create a new filter chain

§Arguments
  • max_hardware_filters - Maximum number of hardware filters supported
Source

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
Source

pub fn remove_filter( &mut self, index: usize, ) -> Result<Box<dyn MessageFilter>, FilterError>

Remove a filter at the given index

§Arguments
  • index - Index of the filter to remove
§Errors

Returns FilterError::FilterNotFound if the index is out of bounds.

Source

pub fn clear(&mut self)

Clear all filters from the chain

Source

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
Source

pub fn len(&self) -> usize

Get the total number of filters

Source

pub fn is_empty(&self) -> bool

Check if the chain is empty

Source

pub fn hardware_filter_count(&self) -> usize

Get the number of hardware filters in use

Source

pub fn software_filter_count(&self) -> usize

Get the number of software filters in use

Source

pub fn max_hardware_filters(&self) -> usize

Get the maximum hardware filter capacity

Source

pub fn has_hardware_capacity(&self) -> bool

Check if hardware filter capacity is available

Source

pub fn total_filter_count(&self) -> usize

Get the total filter count (alias for len)

Source

pub fn iter(&self) -> impl Iterator<Item = &dyn MessageFilter>

Iterate over filters

Source§

impl FilterChain

Source

pub fn from_config(config: &FilterConfig) -> Result<Self, FilterError>

Create a FilterChain from configuration

§Errors

Returns FilterError if any filter configuration is invalid.

Trait Implementations§

Source§

impl Default for FilterChain

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.