screeps_rust_api/
config.rs1#[derive(Debug)]
3pub struct ScreepsConfig {
4 pub token: Option<String>,
6 pub email: Option<String>,
8 pub password: Option<String>,
10 pub host: String,
12 pub secure: bool,
14 pub timeout: u64,
16}
17
18impl ScreepsConfig {
19 pub fn new(
20 token: Option<String>,
21 email: Option<String>,
22 password: Option<String>,
23 host: String,
24 secure: bool,
25 timeout: u64,
26 ) -> Self {
27 Self {
28 token,
29 email,
30 password,
31 host,
32 secure,
33 timeout,
34 }
35 }
36
37 pub fn with_token(&mut self, token: String) {
39 self.token = Some(token);
40 }
41
42 pub fn with_email(&mut self, email: String) {
44 self.email = Some(email);
45 }
46
47 pub fn with_password(&mut self, password: String) {
49 self.password = Some(password);
50 }
51
52 pub fn with_host(&mut self, host: String) {
54 self.host = host;
55 }
56
57 pub fn with_secure(&mut self, secure: bool) {
59 self.secure = secure;
60 }
61
62 pub fn with_timeout(&mut self, timeout: u64) {
64 self.timeout = timeout;
65 }
66
67 pub fn build_base_url(&self) -> String {
69 let protocol = if self.secure { "https" } else { "http" };
70 format!("{}://{}/api", protocol, self.host)
71 }
72}
73
74impl Default for ScreepsConfig {
75 fn default() -> Self {
76 Self {
77 token: None,
78 email: None,
79 password: None,
80 host: "screeps.com".to_string(),
81 secure: true,
82 timeout: 15,
83 }
84 }
85}