testnet/
config.rs

1use ipnet::IpNet;
2
3use crate::Context;
4
5/// Result of the node's `main` function.
6pub type CallbackResult = Result<(), Box<dyn std::error::Error>>;
7
8/// Network configuration.
9///
10/// This includes the `main` function that is executed on each node
11/// and configuration of all the nodes.
12pub struct NetConfig<C: Into<NodeConfig>, F: FnOnce(Context) -> CallbackResult> {
13    /// Nodes' configurations.
14    pub nodes: Vec<C>,
15    /// Closure that is run on each node.
16    pub main: F,
17}
18
19/// Node configuration.
20#[derive(Default, Clone)]
21pub struct NodeConfig {
22    /// Host name.
23    pub name: String,
24    /// Network interface address.
25    pub ifaddr: IpNet,
26}
27
28impl From<String> for NodeConfig {
29    fn from(name: String) -> Self {
30        Self {
31            name,
32            ..Default::default()
33        }
34    }
35}
36
37impl From<&str> for NodeConfig {
38    fn from(name: &str) -> Self {
39        Self {
40            name: name.into(),
41            ..Default::default()
42        }
43    }
44}