Skip to main content

MessageFilter

Trait MessageFilter 

Source
pub trait MessageFilter: Send + Sync {
    // Required method
    fn matches(&self, message: &CanMessage) -> bool;

    // Provided methods
    fn priority(&self) -> u32 { ... }
    fn is_hardware(&self) -> bool { ... }
}
Expand description

Message filter trait

All filter implementations must implement this trait. Filters can be either hardware-accelerated or software-based.

§Thread Safety

Implementations must be Send + Sync to allow use across threads.

§Example

use canlink_hal::filter::MessageFilter;
use canlink_hal::message::CanMessage;

struct MyFilter {
    target_id: u32,
}

impl MessageFilter for MyFilter {
    fn matches(&self, message: &CanMessage) -> bool {
        message.id() == self.target_id
    }
}

Required Methods§

Source

fn matches(&self, message: &CanMessage) -> bool

Check if a message matches this filter

Returns true if the message should be accepted.

Provided Methods§

Source

fn priority(&self) -> u32

Get the filter priority

Higher priority filters are evaluated first. Default is 0 (lowest priority).

Source

fn is_hardware(&self) -> bool

Check if this is a hardware filter

Hardware filters are executed by the CAN controller, reducing CPU load. Returns false by default.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§