Nodes

Struct Nodes 

Source
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

Source

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);
}
Source

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-sensitive
Source

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);
Source

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());
Source

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 bounds
Source§

impl Nodes

Source

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.

Trait Implementations§

Source§

impl Debug for Nodes

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Nodes

Source§

fn default() -> Nodes

Returns the “default value” for a type. Read more
Source§

impl Display for Nodes

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Nodes

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Nodes

Source§

fn eq(&self, other: &Nodes) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Nodes

Source§

impl StructuralPartialEq for Nodes

Auto Trait Implementations§

§

impl Freeze for Nodes

§

impl RefUnwindSafe for Nodes

§

impl Send for Nodes

§

impl Sync for Nodes

§

impl Unpin for Nodes

§

impl UnwindSafe for Nodes

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.