From 98a2c4257e240aaa83e874b60dbaa91ddb72737e Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sat, 9 Mar 2019 22:59:27 +0100 Subject: Implement Default trait for tftpd Configuration --- src/tftpd.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/tftpd.rs b/src/tftpd.rs index c8bd5b5..b84b86e 100644 --- a/src/tftpd.rs +++ b/src/tftpd.rs @@ -34,6 +34,20 @@ struct Configuration { dir: PathBuf, } +impl Default for Configuration { + fn default() -> Configuration { + Configuration { + port: 69, + uid: 65534, + gid: 65534, + ro: false, + wo: false, + threads: 2, + dir: env::current_dir().expect("Can't get current directory"), + } + } +} + #[derive(Clone)] struct Tftpd { tftp: rtftp::Tftp, @@ -288,15 +302,7 @@ fn usage(opts: Options, program: String, error: Option) { fn parse_commandline(args: &[String]) -> Result { let program = args[0].clone(); - let mut conf = Configuration { - port: 69, - uid: 65534, - gid: 65534, - ro: false, - wo: false, - threads: 2, - dir: env::current_dir().expect("Can't get current directory"), - }; + let mut conf: Configuration = Default::default(); let mut opts = Options::new(); opts.optflag("h", "help", "display usage information"); opts.optopt("d", "directory", "directory to serve (default: current directory)", "DIRECTORY"); -- cgit v1.2.3