aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ba633a5..94de64d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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();