pub struct Builder<D = ()> { /* 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<D: SetupData> Builder<D>
impl<D: SetupData> Builder<D>
Sourcepub fn with_setup<F, Fut>(setup_fn: F) -> Builder<D>
pub fn with_setup<F, Fut>(setup_fn: F) -> Builder<D>
Creates a new simulation builder with a setup function for setup data.
The 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.
Sourcepub fn spawn<N: Spawn<D>>(
self,
node_count: u32,
node_builder: impl Into<NodeBuilder<N, D>>,
) -> Self
pub fn spawn<N: Spawn<D>>( self, node_count: u32, node_builder: impl Into<NodeBuilder<N, D>>, ) -> Self
Adds a group of nodes to spawn in this simulation.
Each node will be created using the provided node builder configuration.
You can create a NodeBuilder
from any type that implements Spawn<D>
where
D
is the type returned from Self::with_setup
. If you are not using the setup
step, D
defaults to the unit type ()
.
Sourcepub async fn build(self, name: &str) -> Result<Simulation<D>>
pub async fn build(self, name: &str) -> Result<Simulation<D>>
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.