From 5041abde27e3c1267d1f4930ce1775397b494c48 Mon Sep 17 00:00:00 2001 From: uniminin Date: Sat, 28 Nov 2020 19:26:08 +0600 Subject: [PATCH 1/3] fix typo --- chapter4.md | 2 +- examples/sample4.rs | 2 +- examples/sample5.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chapter4.md b/chapter4.md index e4210a7..a9e9cfe 100644 --- a/chapter4.md +++ b/chapter4.md @@ -256,7 +256,7 @@ fn main() -> Result<()> { loop { match handle_query(&socket) { Ok(_) => {}, - Err(e) => eprintln!("An error occured: {}", e), + Err(e) => eprintln!("An error occurred: {}", e), } } } diff --git a/examples/sample4.rs b/examples/sample4.rs index eee856b..cc680de 100644 --- a/examples/sample4.rs +++ b/examples/sample4.rs @@ -794,7 +794,7 @@ fn main() -> Result<()> { loop { match handle_query(&socket) { Ok(_) => {}, - Err(e) => eprintln!("An error occured: {}", e), + Err(e) => eprintln!("An error occurred: {}", e), } } } diff --git a/examples/sample5.rs b/examples/sample5.rs index 15abd8c..63268f8 100644 --- a/examples/sample5.rs +++ b/examples/sample5.rs @@ -887,7 +887,7 @@ fn main() -> Result<()> { loop { match handle_query(&socket) { Ok(_) => {}, - Err(e) => eprintln!("An error occured: {}", e), + Err(e) => eprintln!("An error occurred: {}", e), } } } From abd3bb9525848476c197d3cf38199c1fcab50486 Mon Sep 17 00:00:00 2001 From: uniminin Date: Sat, 28 Nov 2020 19:27:23 +0600 Subject: [PATCH 2/3] simplify expressions --- examples/sample1.rs | 16 ++++++++-------- examples/sample2.rs | 16 ++++++++-------- examples/sample3.rs | 36 ++++++++++++++++++------------------ examples/sample4.rs | 36 ++++++++++++++++++------------------ examples/sample5.rs | 36 ++++++++++++++++++------------------ 5 files changed, 70 insertions(+), 70 deletions(-) diff --git a/examples/sample1.rs b/examples/sample1.rs index c367fcb..1982113 100644 --- a/examples/sample1.rs +++ b/examples/sample1.rs @@ -301,8 +301,8 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { DnsQuestion { - name: name, - qtype: qtype, + name, + qtype, } } @@ -353,19 +353,19 @@ impl DnsRecord { ); Ok(DnsRecord::A { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::UNKNOWN(_) => { buffer.step(data_len as usize)?; Ok(DnsRecord::UNKNOWN { - domain: domain, + domain, qtype: qtype_num, - data_len: data_len, - ttl: ttl, + data_len, + ttl, }) } } diff --git a/examples/sample2.rs b/examples/sample2.rs index 345291e..aea9745 100644 --- a/examples/sample2.rs +++ b/examples/sample2.rs @@ -337,8 +337,8 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { DnsQuestion { - name: name, - qtype: qtype, + name, + qtype, } } @@ -399,19 +399,19 @@ impl DnsRecord { ); Ok(DnsRecord::A { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::UNKNOWN(_) => { buffer.step(data_len as usize)?; Ok(DnsRecord::UNKNOWN { - domain: domain, + domain, qtype: qtype_num, - data_len: data_len, - ttl: ttl, + data_len, + ttl, }) } } diff --git a/examples/sample3.rs b/examples/sample3.rs index fa8c18c..f074ecf 100644 --- a/examples/sample3.rs +++ b/examples/sample3.rs @@ -362,8 +362,8 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { DnsQuestion { - name: name, - qtype: qtype, + name, + qtype, } } @@ -445,9 +445,9 @@ impl DnsRecord { ); Ok(DnsRecord::A { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::AAAA => { @@ -467,9 +467,9 @@ impl DnsRecord { ); Ok(DnsRecord::AAAA { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::NS => { @@ -477,9 +477,9 @@ impl DnsRecord { buffer.read_qname(&mut ns)?; Ok(DnsRecord::NS { - domain: domain, + domain, host: ns, - ttl: ttl, + ttl, }) } QueryType::CNAME => { @@ -487,9 +487,9 @@ impl DnsRecord { buffer.read_qname(&mut cname)?; Ok(DnsRecord::CNAME { - domain: domain, + domain, host: cname, - ttl: ttl, + ttl, }) } QueryType::MX => { @@ -498,20 +498,20 @@ impl DnsRecord { buffer.read_qname(&mut mx)?; Ok(DnsRecord::MX { - domain: domain, - priority: priority, + domain, + priority, host: mx, - ttl: ttl, + ttl, }) } QueryType::UNKNOWN(_) => { buffer.step(data_len as usize)?; Ok(DnsRecord::UNKNOWN { - domain: domain, + domain, qtype: qtype_num, - data_len: data_len, - ttl: ttl, + data_len, + ttl, }) } } diff --git a/examples/sample4.rs b/examples/sample4.rs index cc680de..b828563 100644 --- a/examples/sample4.rs +++ b/examples/sample4.rs @@ -362,8 +362,8 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { DnsQuestion { - name: name, - qtype: qtype, + name, + qtype, } } @@ -445,9 +445,9 @@ impl DnsRecord { ); Ok(DnsRecord::A { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::AAAA => { @@ -467,9 +467,9 @@ impl DnsRecord { ); Ok(DnsRecord::AAAA { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::NS => { @@ -477,9 +477,9 @@ impl DnsRecord { buffer.read_qname(&mut ns)?; Ok(DnsRecord::NS { - domain: domain, + domain, host: ns, - ttl: ttl, + ttl, }) } QueryType::CNAME => { @@ -487,9 +487,9 @@ impl DnsRecord { buffer.read_qname(&mut cname)?; Ok(DnsRecord::CNAME { - domain: domain, + domain, host: cname, - ttl: ttl, + ttl, }) } QueryType::MX => { @@ -498,20 +498,20 @@ impl DnsRecord { buffer.read_qname(&mut mx)?; Ok(DnsRecord::MX { - domain: domain, - priority: priority, + domain, + priority, host: mx, - ttl: ttl, + ttl, }) } QueryType::UNKNOWN(_) => { buffer.step(data_len as usize)?; Ok(DnsRecord::UNKNOWN { - domain: domain, + domain, qtype: qtype_num, - data_len: data_len, - ttl: ttl, + data_len, + ttl, }) } } diff --git a/examples/sample5.rs b/examples/sample5.rs index 63268f8..b2859c1 100644 --- a/examples/sample5.rs +++ b/examples/sample5.rs @@ -362,8 +362,8 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { DnsQuestion { - name: name, - qtype: qtype, + name, + qtype, } } @@ -445,9 +445,9 @@ impl DnsRecord { ); Ok(DnsRecord::A { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::AAAA => { @@ -467,9 +467,9 @@ impl DnsRecord { ); Ok(DnsRecord::AAAA { - domain: domain, - addr: addr, - ttl: ttl, + domain, + addr, + ttl, }) } QueryType::NS => { @@ -477,9 +477,9 @@ impl DnsRecord { buffer.read_qname(&mut ns)?; Ok(DnsRecord::NS { - domain: domain, + domain, host: ns, - ttl: ttl, + ttl, }) } QueryType::CNAME => { @@ -487,9 +487,9 @@ impl DnsRecord { buffer.read_qname(&mut cname)?; Ok(DnsRecord::CNAME { - domain: domain, + domain, host: cname, - ttl: ttl, + ttl, }) } QueryType::MX => { @@ -498,20 +498,20 @@ impl DnsRecord { buffer.read_qname(&mut mx)?; Ok(DnsRecord::MX { - domain: domain, - priority: priority, + domain, + priority, host: mx, - ttl: ttl, + ttl, }) } QueryType::UNKNOWN(_) => { buffer.step(data_len as usize)?; Ok(DnsRecord::UNKNOWN { - domain: domain, + domain, qtype: qtype_num, - data_len: data_len, - ttl: ttl, + data_len, + ttl, }) } } From 24a949c4d49785b27bfd093c6a526e0b75725329 Mon Sep 17 00:00:00 2001 From: uniminin Date: Sat, 28 Nov 2020 19:29:04 +0600 Subject: [PATCH 3/3] rustfmt examples/*.rs --- examples/sample1.rs | 11 ++--------- examples/sample2.rs | 11 ++--------- examples/sample3.rs | 17 +++-------------- examples/sample4.rs | 19 ++++--------------- examples/sample5.rs | 19 ++++--------------- 5 files changed, 15 insertions(+), 62 deletions(-) diff --git a/examples/sample1.rs b/examples/sample1.rs index 1982113..9ce20a4 100644 --- a/examples/sample1.rs +++ b/examples/sample1.rs @@ -300,10 +300,7 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { - DnsQuestion { - name, - qtype, - } + DnsQuestion { name, qtype } } pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> { @@ -352,11 +349,7 @@ impl DnsRecord { ((raw_addr >> 0) & 0xFF) as u8, ); - Ok(DnsRecord::A { - domain, - addr, - ttl, - }) + Ok(DnsRecord::A { domain, addr, ttl }) } QueryType::UNKNOWN(_) => { buffer.step(data_len as usize)?; diff --git a/examples/sample2.rs b/examples/sample2.rs index aea9745..b754d81 100644 --- a/examples/sample2.rs +++ b/examples/sample2.rs @@ -336,10 +336,7 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { - DnsQuestion { - name, - qtype, - } + DnsQuestion { name, qtype } } pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> { @@ -398,11 +395,7 @@ impl DnsRecord { ((raw_addr >> 0) & 0xFF) as u8, ); - Ok(DnsRecord::A { - domain, - addr, - ttl, - }) + Ok(DnsRecord::A { domain, addr, ttl }) } QueryType::UNKNOWN(_) => { buffer.step(data_len as usize)?; diff --git a/examples/sample3.rs b/examples/sample3.rs index f074ecf..32a3001 100644 --- a/examples/sample3.rs +++ b/examples/sample3.rs @@ -361,10 +361,7 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { - DnsQuestion { - name, - qtype, - } + DnsQuestion { name, qtype } } pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> { @@ -444,11 +441,7 @@ impl DnsRecord { ((raw_addr >> 0) & 0xFF) as u8, ); - Ok(DnsRecord::A { - domain, - addr, - ttl, - }) + Ok(DnsRecord::A { domain, addr, ttl }) } QueryType::AAAA => { let raw_addr1 = buffer.read_u32()?; @@ -466,11 +459,7 @@ impl DnsRecord { ((raw_addr4 >> 0) & 0xFFFF) as u16, ); - Ok(DnsRecord::AAAA { - domain, - addr, - ttl, - }) + Ok(DnsRecord::AAAA { domain, addr, ttl }) } QueryType::NS => { let mut ns = String::new(); diff --git a/examples/sample4.rs b/examples/sample4.rs index b828563..a648131 100644 --- a/examples/sample4.rs +++ b/examples/sample4.rs @@ -361,10 +361,7 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { - DnsQuestion { - name, - qtype, - } + DnsQuestion { name, qtype } } pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> { @@ -444,11 +441,7 @@ impl DnsRecord { ((raw_addr >> 0) & 0xFF) as u8, ); - Ok(DnsRecord::A { - domain, - addr, - ttl, - }) + Ok(DnsRecord::A { domain, addr, ttl }) } QueryType::AAAA => { let raw_addr1 = buffer.read_u32()?; @@ -466,11 +459,7 @@ impl DnsRecord { ((raw_addr4 >> 0) & 0xFFFF) as u16, ); - Ok(DnsRecord::AAAA { - domain, - addr, - ttl, - }) + Ok(DnsRecord::AAAA { domain, addr, ttl }) } QueryType::NS => { let mut ns = String::new(); @@ -793,7 +782,7 @@ fn main() -> Result<()> { // requests is initiated. loop { match handle_query(&socket) { - Ok(_) => {}, + Ok(_) => {} Err(e) => eprintln!("An error occurred: {}", e), } } diff --git a/examples/sample5.rs b/examples/sample5.rs index b2859c1..40555c9 100644 --- a/examples/sample5.rs +++ b/examples/sample5.rs @@ -361,10 +361,7 @@ pub struct DnsQuestion { impl DnsQuestion { pub fn new(name: String, qtype: QueryType) -> DnsQuestion { - DnsQuestion { - name, - qtype, - } + DnsQuestion { name, qtype } } pub fn read(&mut self, buffer: &mut BytePacketBuffer) -> Result<()> { @@ -444,11 +441,7 @@ impl DnsRecord { ((raw_addr >> 0) & 0xFF) as u8, ); - Ok(DnsRecord::A { - domain, - addr, - ttl, - }) + Ok(DnsRecord::A { domain, addr, ttl }) } QueryType::AAAA => { let raw_addr1 = buffer.read_u32()?; @@ -466,11 +459,7 @@ impl DnsRecord { ((raw_addr4 >> 0) & 0xFFFF) as u16, ); - Ok(DnsRecord::AAAA { - domain, - addr, - ttl, - }) + Ok(DnsRecord::AAAA { domain, addr, ttl }) } QueryType::NS => { let mut ns = String::new(); @@ -886,7 +875,7 @@ fn main() -> Result<()> { loop { match handle_query(&socket) { - Ok(_) => {}, + Ok(_) => {} Err(e) => eprintln!("An error occurred: {}", e), } }