mechutil 0.8.0

Utility structures and functions for mechatronics applications.
Documentation
//
// Copyright (C) 2025 Automated Design Corp.. All Rights Reserved.
// Created Date: 2025-02-25 06:41:53
// -----
// Last Modified: 2025-02-25 10:22:05
// -----
//
//

/// A trait for defining filters. Filters are used to determine if a message
/// matches a subscription.
pub trait SubscriptionFilter<R> {
    /// Returns true if the message matches the filter, false otherwise.
    ///
    /// # Parameters
    /// - `message`: The message to be checked against the filter.
    fn matches(&self, message: &R) -> bool;
}

/// A default filter that always returns true. In other words, no filter.
pub struct DefaultSubscriptionFilter;

impl DefaultSubscriptionFilter {
    /// Creates a new DefaultSubscriptionFilter instance.
    pub fn new() -> Self {
        DefaultSubscriptionFilter
    }
}

impl Default for DefaultSubscriptionFilter {
    fn default() -> Self {
        DefaultSubscriptionFilter
    }
}

impl<R> SubscriptionFilter<R> for DefaultSubscriptionFilter {
    fn matches(&self, _message: &R) -> bool {
        true
    }
}