pub struct Nodes { /* private fields */ }Expand description
Represents a collection of node (ECU) names from a DBC file.
The BU_ statement in a DBC file lists all nodes (ECUs) on the CAN bus.
This struct stores the node names as borrowed references.
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM TCM BCM
BO_ 256 Engine : 8 ECM
SG_ RPM : 0|16@1+ (0.25,0) [0|8000] "rpm"
"#)?;
// Access nodes
assert_eq!(dbc.nodes().len(), 3);
assert!(dbc.nodes().contains("ECM"));
assert!(dbc.nodes().contains("TCM"));
// Iterate over nodes
for node in dbc.nodes().iter() {
println!("Node: {}", node);
}§Empty Nodes
A DBC file may have an empty node list (BU_: with no nodes):
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_:
BO_ 256 Engine : 8 ECM
"#)?;
assert!(dbc.nodes().is_empty());§DBC Format
In DBC files, nodes are specified on the BU_ line:
- Format:
BU_: Node1 Node2 Node3 ... - Node names are space-separated
- Maximum of 256 nodes (DoS protection)
- All node names must be unique (case-sensitive)
- Empty node list is valid (
BU_:) - Maximum 32 characters per node name by default
Implementations§
Source§impl Nodes
impl Nodes
Sourcepub fn iter(&self) -> impl Iterator<Item = &str> + '_
pub fn iter(&self) -> impl Iterator<Item = &str> + '_
Returns an iterator over the node names.
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM TCM BCM
"#)?;
// Iterate over nodes
let mut iter = dbc.nodes().iter();
assert_eq!(iter.next(), Some("ECM"));
assert_eq!(iter.next(), Some("TCM"));
assert_eq!(iter.next(), Some("BCM"));
assert_eq!(iter.next(), None);
// Or use in a loop
for node in dbc.nodes().iter() {
println!("Node: {}", node);
}Sourcepub fn contains(&self, node: &str) -> bool
pub fn contains(&self, node: &str) -> bool
Checks if a node name is in the list.
The check is case-sensitive.
§Arguments
node- The node name to check
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM TCM
"#)?;
assert!(dbc.nodes().contains("ECM"));
assert!(dbc.nodes().contains("TCM"));
assert!(!dbc.nodes().contains("BCM"));
assert!(!dbc.nodes().contains("ecm")); // Case-sensitiveSourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of nodes in the collection.
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM TCM BCM
"#)?;
assert_eq!(dbc.nodes().len(), 3);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no nodes in the collection.
§Examples
use dbc_rs::Dbc;
// Empty node list
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_:
"#)?;
assert!(dbc.nodes().is_empty());
// With nodes
let dbc2 = Dbc::parse(r#"VERSION "1.0"
BU_: ECM
"#)?;
assert!(!dbc2.nodes().is_empty());Sourcepub fn at(&self, index: usize) -> Option<&str>
pub fn at(&self, index: usize) -> Option<&str>
Gets a node by index.
Returns None if the index is out of bounds.
§Arguments
index- The zero-based index of the node
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM TCM BCM
"#)?;
assert_eq!(dbc.nodes().at(0), Some("ECM"));
assert_eq!(dbc.nodes().at(1), Some("TCM"));
assert_eq!(dbc.nodes().at(2), Some("BCM"));
assert_eq!(dbc.nodes().at(3), None); // Out of boundsSource§impl Nodes
impl Nodes
Sourcepub fn to_dbc_string(&self) -> String
pub fn to_dbc_string(&self) -> String
Converts the nodes to their DBC file representation.
Returns a string in the format: BU_: Node1 Node2 Node3 ...
§Examples
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_: ECM TCM BCM
"#)?;
let dbc_string = dbc.nodes().to_dbc_string();
assert_eq!(dbc_string, "BU_: ECM TCM BCM");§Empty Nodes
Empty node lists are represented as BU_::
use dbc_rs::Dbc;
let dbc = Dbc::parse(r#"VERSION "1.0"
BU_:
"#)?;
assert_eq!(dbc.nodes().to_dbc_string(), "BU_:");§Feature Requirements
This method requires the std feature to be enabled.