pub struct Builder<C: Ctx = ()> { /* private fields */ }Expand description
Builder for constructing simulation configurations.
Allows configuring the setup function, node spawners, and number of rounds before building the final simulation.
Implementations§
Source§impl<C: Ctx> Builder<C>
impl<C: Ctx> Builder<C>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new simulation builder.
The context’s setup function is called once before the simulation starts to initialize the setup data that will be shared across all nodes.
The setup function can return any type that implements SetupData,
which is an auto-implemented supertrait for all types that are
serializable, cloneable, and thread-safe. See SetupData for details.
§Errors
The setup function should return an error if initialization fails.
pub fn with_config(config: C::Config) -> Self
Sourcepub fn spawn<N: Node<C>>(
self,
node_count: u32,
builder: impl Into<NodeBuilder<N, C>>,
) -> Self
pub fn spawn<N: Node<C>>( self, node_count: u32, builder: impl Into<NodeBuilder<N, C>>, ) -> Self
Adds a group of nodes to spawn in this simulation.
Each node will be created using the provided node builder configuration.
Create a NodeBuilder with NodeBuilder::new(round_fn) for any type
that implements Node<C>. Shared setup data is provided via your
Ctx implementation (Ctx::setup), not via a builder closure.
Sourcepub async fn build(self, name: &str) -> Result<Simulation<C>>
pub async fn build(self, name: &str) -> Result<Simulation<C>>
Builds the final simulation from this configuration.
This method initializes tracing, runs the setup function, and prepares all nodes for execution based on the current run mode.
§Errors
Returns an error if setup fails, tracing initialization fails, or the configuration is invalid for the current run mode.