rpc_json_client/
builder.rs1use crate::RpcClient;
2
3pub struct ClientBuilder {
4 url: String,
5 user: Option<String>,
6 password: Option<String>,
7 retry: bool,
8 backup_urls: Vec<String>,
9}
10
11impl ClientBuilder {
12 pub fn new(url: &str) -> ClientBuilder {
13 ClientBuilder {
14 url: url.to_owned(),
15 user: None,
16 password: None,
17 retry: false,
18 backup_urls: Vec::new(),
19 }
20 }
21
22 pub fn with_user(mut self, username: &str, password: &str) -> Self {
23 self.user = Some(username.to_owned());
24 self.password = Some(password.to_owned());
25 self
26 }
27
28 pub fn with_retry(mut self) -> Self {
29 self.retry = true;
30 self
31 }
32
33 pub fn with_backups(mut self, backup_urls: Vec<String>) -> Self {
34 self.backup_urls = backup_urls;
35 self
36 }
37
38 pub fn build(self) -> RpcClient {
39 RpcClient::new(
40 &self.url,
41 self.user,
42 self.password,
43 self.retry,
44 self.backup_urls,
45 )
46 }
47}