11use std:: fs;
2- use config:: { ConfigError , Config , File } ;
32use std:: path:: Path ;
4- use serde:: { Serialize , Deserialize } ;
3+
4+ use config:: { Config , ConfigError , File } ;
5+ use serde:: { Deserialize , Serialize } ;
56use tokio:: sync:: RwLock ;
67
78#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -14,7 +15,7 @@ pub enum TrackerMode {
1415 Public ,
1516 Private ,
1617 Whitelisted ,
17- PrivateWhitelisted
18+ PrivateWhitelisted ,
1819}
1920
2021#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -36,7 +37,7 @@ pub struct Network {
3637pub enum EmailOnSignup {
3738 Required ,
3839 Optional ,
39- None
40+ None ,
4041}
4142
4243#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -76,35 +77,35 @@ pub struct TorrustConfig {
7677
7778#[ derive( Debug ) ]
7879pub struct Configuration {
79- pub settings : RwLock < TorrustConfig >
80+ pub settings : RwLock < TorrustConfig > ,
8081}
8182
8283impl Configuration {
8384 pub fn default ( ) -> Configuration {
8485 let torrust_config = TorrustConfig {
8586 website : Website {
86- name : "Torrust" . to_string ( )
87+ name : "Torrust" . to_string ( ) ,
8788 } ,
8889 tracker : Tracker {
8990 url : "udp://localhost:6969" . to_string ( ) ,
9091 mode : TrackerMode :: Public ,
9192 api_url : "http://localhost:1212" . to_string ( ) ,
9293 token : "MyAccessToken" . to_string ( ) ,
93- token_valid_seconds : 7257600
94+ token_valid_seconds : 7257600 ,
9495 } ,
9596 net : Network {
9697 port : 3000 ,
97- base_url : None
98+ base_url : None ,
9899 } ,
99100 auth : Auth {
100101 email_on_signup : EmailOnSignup :: Optional ,
101102 min_password_length : 6 ,
102103 max_password_length : 64 ,
103- secret_key : "MaxVerstappenWC2021" . to_string ( )
104+ secret_key : "MaxVerstappenWC2021" . to_string ( ) ,
104105 } ,
105106 database : Database {
106107 connect_url : "sqlite://data.db?mode=rwc" . to_string ( ) ,
107- torrent_info_update_interval : 3600
108+ torrent_info_update_interval : 3600 ,
108109 } ,
109110 mail : Mail {
110111 email_verification_enabled : false ,
@@ -113,12 +114,12 @@ impl Configuration {
113114 username : "" . to_string ( ) ,
114115 password : "" . to_string ( ) ,
115116 server : "" . to_string ( ) ,
116- port : 25
117- }
117+ port : 25 ,
118+ } ,
118119 } ;
119120
120121 Configuration {
121- settings : RwLock :: new ( torrust_config)
122+ settings : RwLock :: new ( torrust_config) ,
122123 }
123124 }
124125
@@ -134,7 +135,9 @@ impl Configuration {
134135 eprintln ! ( "Creating config file.." ) ;
135136 let config = Configuration :: default ( ) ;
136137 let _ = config. save_to_file ( ) . await ;
137- return Err ( ConfigError :: Message ( format ! ( "Please edit the config.TOML in the root folder and restart the tracker." ) ) )
138+ return Err ( ConfigError :: Message ( format ! (
139+ "Please edit the config.TOML in the root folder and restart the tracker."
140+ ) ) ) ;
138141 }
139142
140143 let torrust_config: TorrustConfig = match config. try_into ( ) {
@@ -143,11 +146,11 @@ impl Configuration {
143146 } ?;
144147
145148 Ok ( Configuration {
146- settings : RwLock :: new ( torrust_config)
149+ settings : RwLock :: new ( torrust_config) ,
147150 } )
148151 }
149152
150- pub async fn save_to_file ( & self ) -> Result < ( ) , ( ) > {
153+ pub async fn save_to_file ( & self ) -> Result < ( ) , ( ) > {
151154 let settings = self . settings . read ( ) . await ;
152155
153156 let toml_string = toml:: to_string ( & * settings) . expect ( "Could not encode TOML value" ) ;
@@ -178,7 +181,7 @@ impl Configuration {
178181 website_name : settings_lock. website . name . clone ( ) ,
179182 tracker_url : settings_lock. tracker . url . clone ( ) ,
180183 tracker_mode : settings_lock. tracker . mode . clone ( ) ,
181- email_on_signup : settings_lock. auth . email_on_signup . clone ( )
184+ email_on_signup : settings_lock. auth . email_on_signup . clone ( ) ,
182185 }
183186 }
184187}
@@ -188,5 +191,5 @@ pub struct ConfigurationPublic {
188191 website_name : String ,
189192 tracker_url : String ,
190193 tracker_mode : TrackerMode ,
191- email_on_signup : EmailOnSignup
194+ email_on_signup : EmailOnSignup ,
192195}
0 commit comments