use core::ops::BitOr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct FeatureFlags(pub u32);
impl FeatureFlags {
pub const ISOCHRONOUS: Self = Self(1 << 0);
pub const SDO_UDP: Self = Self(1 << 1);
pub const SDO_ASND: Self = Self(1 << 2);
pub const SDO_PDO: Self = Self(1 << 3);
pub const NMT_INFO_SERVICES: Self = Self(1 << 4);
pub const EXTENDED_NMT_CMDS: Self = Self(1 << 5);
pub const DYNAMIC_PDO_MAPPING: Self = Self(1 << 6);
pub const NMT_SERVICE_UDP: Self = Self(1 << 7);
pub const CONFIG_MANAGER: Self = Self(1 << 8);
pub const MULTIPLEXED_ACCESS: Self = Self(1 << 9);
pub const NODE_ID_BY_SW: Self = Self(1 << 10);
pub const MN_BASIC_ETHERNET: Self = Self(1 << 11);
pub const ROUTING_TYPE_1: Self = Self(1 << 12);
pub const ROUTING_TYPE_2: Self = Self(1 << 13);
pub const SDO_RW_ALL_BY_INDEX: Self = Self(1 << 14);
pub const SDO_RW_MULTIPLE_BY_INDEX: Self = Self(1 << 15);
pub fn from_bits_truncate(bits: u32) -> Self {
Self(bits)
}
pub fn contains(&self, other: Self) -> bool {
(self.0 & other.0) == other.0
}
pub fn empty() -> Self {
Self(0)
}
pub fn insert(&mut self, other: Self) {
self.0 |= other.0;
}
pub fn remove(&mut self, other: Self) {
self.0 &= !other.0;
}
}
impl BitOr for FeatureFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_bitor_implementation() {
let flags1 = FeatureFlags::ISOCHRONOUS; let flags2 = FeatureFlags::SDO_ASND;
let combined = flags1 | flags2;
assert_eq!(combined.0, 0b0000_0101); assert!(combined.contains(FeatureFlags::ISOCHRONOUS));
assert!(combined.contains(FeatureFlags::SDO_ASND));
assert!(!combined.contains(FeatureFlags::SDO_UDP));
}
}