dbc_rs/nodes/mod.rs
1mod impls;
2mod parse;
3#[cfg(feature = "std")]
4mod std;
5mod validate;
6
7#[cfg(feature = "std")]
8mod builder;
9
10use crate::{
11 MAX_NODES,
12 compat::{Name, Vec},
13};
14#[cfg(feature = "std")]
15pub use builder::NodesBuilder;
16
17type NodeNames = Vec<Name, { MAX_NODES }>;
18
19/// Represents a collection of node (ECU) names from a DBC file.
20///
21/// The `BU_` statement in a DBC file lists all nodes (ECUs) on the CAN bus.
22/// This struct stores the node names as borrowed references.
23///
24/// # Examples
25///
26/// ```rust,no_run
27/// use dbc_rs::Dbc;
28///
29/// let dbc = Dbc::parse(r#"VERSION "1.0"
30///
31/// BU_: ECM TCM BCM
32///
33/// BO_ 256 Engine : 8 ECM
34/// SG_ RPM : 0|16@1+ (0.25,0) [0|8000] "rpm"
35/// "#)?;
36///
37/// // Access nodes
38/// assert_eq!(dbc.nodes().len(), 3);
39/// assert!(dbc.nodes().contains("ECM"));
40/// assert!(dbc.nodes().contains("TCM"));
41///
42/// // Iterate over nodes
43/// for node in dbc.nodes().iter() {
44/// println!("Node: {}", node);
45/// }
46/// # Ok::<(), dbc_rs::Error>(())
47/// ```
48///
49/// # Empty Nodes
50///
51/// A DBC file may have an empty node list (`BU_:` with no nodes):
52///
53/// ```rust,no_run
54/// use dbc_rs::Dbc;
55///
56/// let dbc = Dbc::parse(r#"VERSION "1.0"
57///
58/// BU_:
59///
60/// BO_ 256 Engine : 8 ECM
61/// "#)?;
62///
63/// assert!(dbc.nodes().is_empty());
64/// # Ok::<(), dbc_rs::Error>(())
65/// ```
66///
67/// # DBC Format
68///
69/// In DBC files, nodes are specified on the `BU_` line:
70/// - Format: `BU_: Node1 Node2 Node3 ...`
71/// - Node names are space-separated
72/// - Maximum of 256 nodes (DoS protection)
73/// - All node names must be unique (case-sensitive)
74/// - Empty node list is valid (`BU_:`)
75/// - Maximum 32 characters per node name by default
76#[derive(Debug, Default, PartialEq, Eq, Hash, Clone)]
77pub struct Nodes {
78 nodes: NodeNames,
79}