can_types/
identifier.rs

1// Copyright (c) 2024 Nathan H. Keough
2//
3// This work is dual-licensed under MIT OR Apache 2.0 (or any later version).
4// You may choose between one of them if you use this work.
5//
6// For further detail, please refer to the individual licenses located at the root of this crate.
7
8//! Defines the `Id` type representing a Controller Area Network (CAN) identifier
9//! specific to a protocol.
10//!
11//! Generics are employed here for flexibility and performance benefits. By parameterizing [`Id`]
12//! over different protocol types (P) that conform to the [`IsProtocol`] trait, Rust's
13//! monomorphization ensures efficient code generation at compile-time while avoiding namespace
14//! pollution from dozens of individual types.
15
16/// Marks a type, relating it to a specific protocol.
17pub trait IsProtocol {}
18
19/// Represents a Controller Area Network (CAN) identifier of a specific protocol.
20#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
21pub struct Id<P: IsProtocol>(pub(crate) P);