dbc_rs/nodes/builder/
mod.rs

1use std::{string::String, vec::Vec};
2
3/// Builder for creating `Nodes` programmatically.
4///
5/// This builder allows you to construct node lists when building DBC files
6/// programmatically. It validates that node names are unique and within limits.
7///
8/// # Examples
9///
10/// ```rust,no_run
11/// use dbc_rs::NodesBuilder;
12///
13/// let nodes = NodesBuilder::new()
14///     .add_node("ECM")
15///     .add_node("TCM")
16///     .add_node("BCM")
17///     .build()?;
18///
19/// assert_eq!(nodes.len(), 3);
20/// assert!(nodes.contains("ECM"));
21/// # Ok::<(), dbc_rs::Error>(())
22/// ```
23///
24/// # Adding Comments
25///
26/// You can add comments to nodes using `add_node_with_comment`:
27///
28/// ```rust,no_run
29/// use dbc_rs::NodesBuilder;
30///
31/// let nodes = NodesBuilder::new()
32///     .add_node_with_comment("ECM", "Engine Control Module")
33///     .add_node("TCM")
34///     .build()?;
35///
36/// assert_eq!(nodes.node_comment("ECM"), Some("Engine Control Module"));
37/// assert_eq!(nodes.node_comment("TCM"), None);
38/// # Ok::<(), dbc_rs::Error>(())
39/// ```
40///
41/// # Validation
42///
43/// The builder validates:
44/// - Maximum of 256 nodes (DoS protection)
45/// - All node names must be unique (case-sensitive)
46/// - Maximum 32 characters per node name
47/// - Maximum number of nodes (implementation limit for DoS protection)
48///
49/// # Feature Requirements
50///
51/// This builder requires the `std` feature to be enabled.
52#[derive(Debug, Clone)]
53pub struct NodesBuilder {
54    nodes: Vec<(String, Option<String>)>,
55}
56
57mod build;
58mod impls;