NodesBuilder

Struct NodesBuilder 

Source
pub struct NodesBuilder { /* private fields */ }
Expand description

Builder for creating Nodes programmatically.

This builder allows you to construct node lists when building DBC files programmatically. It validates that node names are unique and within limits.

§Examples

use dbc_rs::NodesBuilder;

let nodes = NodesBuilder::new()
    .add_node("ECM")
    .add_node("TCM")
    .add_node("BCM")
    .build()?;

assert_eq!(nodes.len(), 3);
assert!(nodes.contains("ECM"));

§Validation

The builder validates:

  • Maximum of 256 nodes (DoS protection)
  • No duplicate node names (case-sensitive)

§Feature Requirements

This builder requires the alloc feature to be enabled.

Implementations§

Source§

impl NodesBuilder

Source

pub fn new() -> Self

Creates a new NodesBuilder with an empty node list.

§Examples
use dbc_rs::NodesBuilder;

let builder = NodesBuilder::new();
let nodes = builder.build()?;
assert!(nodes.is_empty());
Source

pub fn add_node(self, node: impl AsRef<str>) -> Self

Adds a single node to the list.

§Arguments
  • node - The node name (anything that implements AsRef<str>)
§Examples
use dbc_rs::NodesBuilder;

let nodes = NodesBuilder::new()
    .add_node("ECM")
    .add_node("TCM")
    .build()?;
assert_eq!(nodes.len(), 2);
Source

pub fn add_nodes<I, S>(self, nodes: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Adds multiple nodes from an iterator.

§Arguments
  • nodes - An iterator of node names (each item must implement AsRef<str>)
§Examples
use dbc_rs::NodesBuilder;

// From a slice
let nodes = NodesBuilder::new()
    .add_nodes(&["ECM", "TCM", "BCM"])
    .build()?;
assert_eq!(nodes.len(), 3);

// From a vector
let node_vec = vec!["Node1", "Node2"];
let nodes2 = NodesBuilder::new()
    .add_nodes(node_vec.iter())
    .build()?;
assert_eq!(nodes2.len(), 2);
Source

pub fn clear(self) -> Self

Clears all nodes from the builder.

§Examples
use dbc_rs::NodesBuilder;

let nodes = NodesBuilder::new()
    .add_node("ECM")
    .add_node("TCM")
    .clear()
    .add_node("BCM")
    .build()?;
assert_eq!(nodes.len(), 1);
assert!(nodes.contains("BCM"));
assert!(!nodes.contains("ECM"));
Source

pub fn validate(self) -> Result<Self>

Validates the current builder state without building.

This is useful for checking if the configuration is valid before building. Returns a new builder with validated nodes, or an error if validation fails.

§Returns

Returns Ok(Self) if validation succeeds, or Err(Error::Nodes) if:

  • More than 256 nodes are specified (exceeds maximum limit)
  • Duplicate node names are found (case-sensitive)
§Examples
use dbc_rs::NodesBuilder;

// Valid configuration
let builder = NodesBuilder::new()
    .add_node("ECM")
    .add_node("TCM");
assert!(builder.validate().is_ok());

// Invalid: duplicate nodes
let builder2 = NodesBuilder::new()
    .add_node("ECM")
    .add_node("ECM"); // Duplicate
assert!(builder2.validate().is_err());
Source

pub fn build(self) -> Result<Nodes<'static>>

Builds the Nodes from the builder configuration.

This validates the nodes and constructs a Nodes instance with static lifetime.

§Returns

Returns Ok(Nodes) if successful, or Err(Error::Nodes) if:

  • More than 256 nodes are specified (exceeds maximum limit)
  • Duplicate node names are found (case-sensitive)
§Examples
use dbc_rs::NodesBuilder;

// Build with nodes
let nodes = NodesBuilder::new()
    .add_node("ECM")
    .add_node("TCM")
    .build()?;
assert_eq!(nodes.len(), 2);

// Build empty
let empty = NodesBuilder::new().build()?;
assert!(empty.is_empty());
§Errors
use dbc_rs::NodesBuilder;

// Duplicate nodes
let result = NodesBuilder::new()
    .add_node("ECM")
    .add_node("ECM") // Duplicate
    .build();
assert!(result.is_err());

// Too many nodes (limit is 256)
let mut builder = NodesBuilder::new();
for i in 0..257 {
    builder = builder.add_node(format!("Node{i}"));
}
assert!(builder.build().is_err());

Trait Implementations§

Source§

impl Debug for NodesBuilder

Source§

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

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

impl Default for NodesBuilder

Source§

fn default() -> NodesBuilder

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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.