1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
use crate::StratumServer; #[derive(Default)] pub struct StratumServerBuilder<State> { pub host: String, pub port: u16, pub max_connections: Option<usize>, pub proxy: bool, pub var_diff: bool, pub initial_difficulty: f64, pub state: State, } impl<State: Clone + Send + Sync + 'static> StratumServerBuilder<State> { pub fn new(state: State) -> Self { Self { host: String::from(""), port: 0, max_connections: None, proxy: false, var_diff: false, initial_difficulty: 0.0, state, } } pub fn with_host(mut self, host: &str) -> Self { self.host = host.to_owned(); self } pub fn with_port(mut self, port: u16) -> Self { self.port = port; self } pub fn with_max_connections(mut self, max_connections: usize) -> Self { self.max_connections = Some(max_connections); self } pub fn with_proxy(mut self) -> Self { self.proxy = true; self } pub fn with_var_diff(mut self) -> Self { self.var_diff = true; self } pub fn with_initial_difficulty(mut self, difficulty: f64) -> Self { self.initial_difficulty = difficulty; self } pub fn build(mut self) -> StratumServer<State> { StratumServer::new( &self.host, self.port, self.max_connections, self.proxy, self.var_diff, self.initial_difficulty, self.state, ) } }