@@ -23,7 +23,7 @@ pub const ENABLE_COMPRESSION: bool = false;
2323pub const ENABLE_ENCRYPTION : bool = true ;
2424
2525/// Main network configuration structure that contains all configurable settings
26- #[ derive( Debug , Clone , Deserialize , Serialize ) ]
26+ #[ derive( Debug , Clone , Deserialize , Serialize , Default ) ]
2727pub struct NetworkConfig {
2828 /// Server-specific configuration
2929 #[ serde( default ) ]
@@ -42,34 +42,25 @@ pub struct NetworkConfig {
4242 pub logging : LoggingConfig ,
4343}
4444
45- impl Default for NetworkConfig {
46- fn default ( ) -> Self {
47- Self {
48- server : ServerConfig :: default ( ) ,
49- client : ClientConfig :: default ( ) ,
50- transport : TransportConfig :: default ( ) ,
51- logging : LoggingConfig :: default ( ) ,
52- }
53- }
54- }
45+ // Default implementation is now derived
5546
5647impl NetworkConfig {
5748 /// Load configuration from a TOML file
5849 pub fn from_file < P : AsRef < Path > > ( path : P ) -> Result < Self > {
5950 let mut file = File :: open ( path)
60- . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to open config file: {}" , e ) ) ) ?;
51+ . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to open config file: {e}" ) ) ) ?;
6152
6253 let mut contents = String :: new ( ) ;
6354 file. read_to_string ( & mut contents)
64- . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to read config file: {}" , e ) ) ) ?;
55+ . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to read config file: {e}" ) ) ) ?;
6556
6657 Self :: from_toml ( & contents)
6758 }
6859
6960 /// Load configuration from TOML string
7061 pub fn from_toml ( content : & str ) -> Result < Self > {
7162 toml:: from_str :: < Self > ( content)
72- . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to parse TOML: {}" , e ) ) )
63+ . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to parse TOML: {e}" ) ) )
7364 }
7465
7566 /// Load configuration from environment variables
@@ -122,10 +113,10 @@ impl NetworkConfig {
122113 /// Save configuration to a file
123114 pub fn save_to_file < P : AsRef < Path > > ( & self , path : P ) -> Result < ( ) > {
124115 let content = toml:: to_string_pretty ( self )
125- . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to serialize config: {}" , e ) ) ) ?;
116+ . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to serialize config: {e}" ) ) ) ?;
126117
127118 std:: fs:: write ( path, content)
128- . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to write config file: {}" , e ) ) ) ?;
119+ . map_err ( |e| ProtocolError :: ConfigError ( format ! ( "Failed to write config file: {e}" ) ) ) ?;
129120
130121 Ok ( ( ) )
131122 }
@@ -328,6 +319,6 @@ mod log_level_serde {
328319 {
329320 let level_str = String :: deserialize ( deserializer) ?;
330321 Level :: from_str ( & level_str)
331- . map_err ( |_| serde:: de:: Error :: custom ( format ! ( "Invalid log level: {}" , level_str ) ) )
322+ . map_err ( |_| serde:: de:: Error :: custom ( format ! ( "Invalid log level: {level_str}" ) ) )
332323 }
333324}
0 commit comments