فهرست منبع

Use bitwise operators when doing bitwise stuff

I temporarily turned on the 'clippy::integer_arithmetic' lint, and it flagged this entire function. Even though there's no danger of it overflowing, it's better to be clear that there's no actual arithmetic going on here, just bitwise operations.
Benjamin Sago 4 سال پیش
والد
کامیت
cd8ca50126
1فایلهای تغییر یافته به همراه8 افزوده شده و 8 حذف شده
  1. 8 8
      dns/src/wire.rs

+ 8 - 8
dns/src/wire.rs

@@ -272,18 +272,18 @@ impl Flags {
     /// Converts the flags into a two-byte number.
     pub fn to_u16(self) -> u16 {                 // 0123 4567 89AB CDEF
         let mut                          bits  = 0b_0000_0000_0000_0000;
-        if self.response               { bits += 0b_1000_0000_0000_0000; }
+        if self.response               { bits |= 0b_1000_0000_0000_0000; }
         match self.opcode {
-            Opcode::Query     =>       { bits += 0b_0000_0000_0000_0000; }
+            Opcode::Query     =>       { bits |= 0b_0000_0000_0000_0000; }
             Opcode::Other(_)  =>       { unimplemented!(); }
         }
-        if self.authoritative          { bits += 0b_0000_0100_0000_0000; }
-        if self.truncated              { bits += 0b_0000_0010_0000_0000; }
-        if self.recursion_desired      { bits += 0b_0000_0001_0000_0000; }
-        if self.recursion_available    { bits += 0b_0000_0000_1000_0000; }
+        if self.authoritative          { bits |= 0b_0000_0100_0000_0000; }
+        if self.truncated              { bits |= 0b_0000_0010_0000_0000; }
+        if self.recursion_desired      { bits |= 0b_0000_0001_0000_0000; }
+        if self.recursion_available    { bits |= 0b_0000_0000_1000_0000; }
         // (the Z bit is reserved)               0b_0000_0000_0100_0000
-        if self.authentic_data         { bits += 0b_0000_0000_0010_0000; }
-        if self.checking_disabled      { bits += 0b_0000_0000_0001_0000; }
+        if self.authentic_data         { bits |= 0b_0000_0000_0010_0000; }
+        if self.checking_disabled      { bits |= 0b_0000_0000_0001_0000; }
 
         bits
     }