浏览代码

Use Self type where possible

(The 'use_self' Clippy lint)
Benjamin Sago 4 年之前
父节点
当前提交
d902d07cac

+ 1 - 1
dns/src/record/a.rs

@@ -31,7 +31,7 @@ impl Wire for A {
         if let [a, b, c, d] = *buf {
             let address = Ipv4Addr::new(a, b, c, d);
             trace!("Parsed IPv4 address -> {:?}", address);
-            Ok(A { address })
+            Ok(Self { address })
         }
         else {
             warn!("Length is incorrect (record length {:?}, but should be four)", len);

+ 1 - 1
dns/src/record/aaaa.rs

@@ -33,7 +33,7 @@ impl Wire for AAAA {
             // probably the best two lines of code I have ever written
 
             trace!("Parsed IPv6 address -> {:?}", address);
-            Ok(AAAA { address })
+            Ok(Self { address })
         }
         else {
             warn!("Length is incorrect (record length {:?}, but should be sixteen)", len);

+ 1 - 1
dns/src/record/caa.rs

@@ -60,7 +60,7 @@ impl Wire for CAA {
         if len == got_len {
             // This one’s a little weird, because remaining_len is based on len
             trace!("Length is correct");
-            Ok(CAA { critical, tag, value })
+            Ok(Self { critical, tag, value })
         }
         else {
             warn!("Length is incorrect (record length {:?}, flags plus tag plus data length {:?}", len, got_len);

+ 1 - 1
dns/src/record/cname.rs

@@ -27,7 +27,7 @@ impl Wire for CNAME {
 
         if len == domain_len {
             trace!("Length is correct");
-            Ok(CNAME { domain })
+            Ok(Self { domain })
         }
         else {
             warn!("Length is incorrect (record length {:?}, domain length {:?})", len, domain_len);

+ 1 - 1
dns/src/record/mx.rs

@@ -36,7 +36,7 @@ impl Wire for MX {
         let got_len = 2 + exchange_len;
         if len == got_len {
             trace!("Length is correct");
-            Ok(MX { preference, exchange })
+            Ok(Self { preference, exchange })
         }
         else {
             warn!("Length is incorrect (record length {:?}, preference plus exchange length {:?}", len, got_len);

+ 1 - 1
dns/src/record/ns.rs

@@ -28,7 +28,7 @@ impl Wire for NS {
 
         if len == nameserver_len {
             trace!("Length is correct");
-            Ok(NS { nameserver })
+            Ok(Self { nameserver })
         }
         else {
             warn!("Length is incorrect (record length {:?}, nameserver length {:?}", len, nameserver_len);

+ 1 - 1
dns/src/record/opt.rs

@@ -83,7 +83,7 @@ impl OPT {
         }
         trace!("Parsed data -> {:#x?}", data);
 
-        Ok(OPT { udp_payload_size, higher_bits, edns0_version, flags, data })
+        Ok(Self { udp_payload_size, higher_bits, edns0_version, flags, data })
     }
 
     /// Serialises this OPT record into a vector of bytes.

+ 1 - 1
dns/src/record/ptr.rs

@@ -33,7 +33,7 @@ impl Wire for PTR {
 
         if len == cname_len {
             trace!("Length is correct");
-            Ok(PTR { cname })
+            Ok(Self { cname })
         }
         else {
             warn!("Length is incorrect (record length {:?}, cname length {:?}", len, cname_len);

+ 1 - 1
dns/src/record/soa.rs

@@ -71,7 +71,7 @@ impl Wire for SOA {
         let got_len = 4 * 5 + mname_len + rname_len;
         if len == got_len {
             trace!("Length is correct");
-            Ok(SOA {
+            Ok(Self {
                 mname, rname, serial, refresh_interval,
                 retry_interval, expire_limit, minimum_ttl,
             })

+ 1 - 1
dns/src/record/srv.rs

@@ -49,7 +49,7 @@ impl Wire for SRV {
         let got_len = 3 * 2 + target_len;
         if len == got_len {
             trace!("Length is correct");
-            Ok(SRV { priority, weight, port, target })
+            Ok(Self { priority, weight, port, target })
         }
         else {
             warn!("Length is incorrect (record length {:?}, fields plus target length {:?})", len, got_len);

+ 1 - 1
dns/src/record/txt.rs

@@ -58,7 +58,7 @@ impl Wire for TXT {
 
         if len == total_len {
             trace!("Length is correct");
-            Ok(TXT { message })
+            Ok(Self { message })
         }
         else {
             warn!("Length is incorrect (record length {:?}, message length {:?})", len, total_len);

+ 17 - 17
dns/src/wire.rs

@@ -101,7 +101,7 @@ impl Response {
             additionals.push(Answer::from_bytes(qname, &mut c)?);
         }
 
-        Ok(Response { transaction_id, flags, queries, answers, authorities, additionals })
+        Ok(Self { transaction_id, flags, queries, answers, authorities, additionals })
     }
 }
 
@@ -118,7 +118,7 @@ impl Query {
         let qclass = QClass::from_u16(c.read_u16::<BigEndian>()?);
         trace!("Read qclass -> {:?}", qtype);
 
-        Ok(Query { qtype, qclass, qname })
+        Ok(Self { qtype, qclass, qname })
     }
 }
 
@@ -134,7 +134,7 @@ impl Answer {
 
         if qtype == OPT::RR_TYPE {
             let opt = OPT::read(c)?;
-            Ok(Answer::Pseudo { qname, opt })
+            Ok(Self::Pseudo { qname, opt })
         }
         else {
             let qclass = QClass::from_u16(c.read_u16::<BigEndian>()?);
@@ -147,7 +147,7 @@ impl Answer {
             trace!("Read record length -> {:?}", record_length);
 
             let record = Record::from_bytes(qtype, record_length, c)?;
-            Ok(Answer::Standard { qclass, qname, record, ttl })
+            Ok(Self::Standard { qclass, qname, record, ttl })
         }
 
     }
@@ -159,14 +159,14 @@ impl Record {
     /// Reads at most `len` bytes from the given curser, and parses them into
     /// a record structure depending on the type number, which has already been read.
     #[cfg_attr(all(test, feature = "with_mutagen"), ::mutagen::mutate)]
-    fn from_bytes(qtype: TypeInt, len: u16, c: &mut Cursor<&[u8]>) -> Result<Record, WireError> {
+    fn from_bytes(qtype: TypeInt, len: u16, c: &mut Cursor<&[u8]>) -> Result<Self, WireError> {
         use crate::record::*;
 
         macro_rules! try_record {
             ($record:tt) => {
                 if $record::RR_TYPE == qtype {
                     info!("Parsing {} record (type {}, len {})", $record::NAME, qtype, len);
-                    return Wire::read(len, c).map(Record::$record)
+                    return Wire::read(len, c).map(Self::$record)
                 }
             }
         }
@@ -193,7 +193,7 @@ impl Record {
         }
 
         let type_number = UnknownQtype::from(qtype);
-        Ok(Record::Other { type_number, bytes })
+        Ok(Self::Other { type_number, bytes })
     }
 }
 
@@ -201,19 +201,19 @@ impl Record {
 impl QClass {
     fn from_u16(uu: u16) -> Self {
         match uu {
-            0x0001 => QClass::IN,
-            0x0003 => QClass::CH,
-            0x0004 => QClass::HS,
-                 _ => QClass::Other(uu),
+            0x0001 => Self::IN,
+            0x0003 => Self::CH,
+            0x0004 => Self::HS,
+                 _ => Self::Other(uu),
         }
     }
 
     fn to_u16(self) -> u16 {
         match self {
-            QClass::IN        => 0x0001,
-            QClass::CH        => 0x0003,
-            QClass::HS        => 0x0004,
-            QClass::Other(uu) => uu,
+            Self::IN        => 0x0001,
+            Self::CH        => 0x0003,
+            Self::HS        => 0x0004,
+            Self::Other(uu) => uu,
         }
     }
 }
@@ -276,7 +276,7 @@ impl Flags {
     pub fn from_u16(bits: u16) -> Self {
         let has_bit = |bit| { bits & bit == bit };
 
-        Flags {
+        Self {
             response:               has_bit(0b_1000_0000_0000_0000),
             opcode:                 0,
             authoritative:          has_bit(0b_0000_0100_0000_0000),
@@ -419,6 +419,6 @@ pub enum WireError {
 impl From<io::Error> for WireError {
     fn from(ioe: io::Error) -> Self {
         error!("IO error -> {:?}", ioe);
-        WireError::IO
+        Self::IO
     }
 }