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)
  • All node names must be unique (case-sensitive)
  • Maximum 32 characters per node name
  • Maximum number of nodes (implementation limit for DoS protection)

§Feature Requirements

This builder requires the std 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::Validation) if:

  • Too many nodes are specified (exceeds 256 nodes limit by default)
  • Duplicate node names are found (case-sensitive)
  • Node name exceeds maximum length (32 characters by default)
§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>

Builds the Nodes from the builder configuration.

This validates the nodes and constructs a Nodes instance.

§Returns

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

  • Too many nodes are specified (exceeds 256 nodes limit by default)
  • Duplicate node names are found (case-sensitive)
  • Node name exceeds maximum length (32 characters)
§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());

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() -> Self

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

Auto Trait Implementations§

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, 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.