diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2022-07-09 21:47:26 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2022-07-09 21:47:26 +0200 |
| commit | 7e1cade440763e5af9aa185e861cb4d951ca0c9a (patch) | |
| tree | 569a584e6923dbb7937e8b9f53a1a133446c863e /src/lib.rs | |
| parent | f26db1f2b1d9e6235402f878f1559b327e9e7c41 (diff) | |
Use Default trait for options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 35 |
1 files changed, 14 insertions, 21 deletions
@@ -29,9 +29,10 @@ pub enum Opcode { OACK = 0x06, } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Default)] #[repr(u8)] pub enum Mode { + #[default] OCTET, NETASCII, } @@ -43,21 +44,23 @@ pub struct TftpOptions { tsize: u64, } -#[derive(Clone, Copy)] +impl Default for TftpOptions { + fn default() -> Self { + TftpOptions { + blksize: 512, + timeout: Duration::from_secs(3), + tsize: 0, + } + } +} + +#[derive(Clone, Copy, Default)] pub struct Tftp { options: TftpOptions, mode: Mode, progress_cb: Option<ProgressCallback>, } -fn default_options() -> TftpOptions { - TftpOptions { - blksize: 512, - timeout: Duration::from_secs(3), - tsize: 0, - } -} - fn netascii_to_octet(buf: &[u8], previous_cr: bool) -> (Vec<u8>, bool) { let mut out = Vec::with_capacity(buf.len()); @@ -98,16 +101,6 @@ fn blksize2(size: usize) -> usize { } -impl Default for Tftp { - fn default() -> Tftp { - Tftp { - options: default_options(), - mode: Mode::OCTET, - progress_cb: None, - } - } -} - impl Tftp { pub fn new() -> Tftp { Default::default() @@ -298,7 +291,7 @@ impl Tftp { } pub fn init_tftp_options(&mut self, sock: &UdpSocket, options: &mut HashMap<String, String>) -> Result<(), io::Error> { - self.options = default_options(); + self.options = Default::default(); options.retain(|key, val| { let val = val.to_lowercase(); |
