Skip to content

Commit

Permalink
Apply various Clippy-suggested fixes. (#223)
Browse files Browse the repository at this point in the history
This PR applies various fixes suggested by recently added
Clippy lints. As a consequence it also fixes a test that previously
was never compiled due to a misspelled cfg attr.
  • Loading branch information
partim authored Sep 15, 2023
1 parent cb12b52 commit 8ec0840
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/base/iana/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ macro_rules! int_enum {
fn partial_cmp(
&self, other: &Self
) -> Option<core::cmp::Ordering> {
self.to_int().partial_cmp(&other.to_int())
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/base/iana/rcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl cmp::Eq for Rcode {}

impl cmp::PartialOrd for Rcode {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.to_int().partial_cmp(&other.to_int())
Some(self.cmp(other))
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/base/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,7 @@ impl<'a, Octs: Octets + ?Sized> QuestionSection<'a, Octs> {

impl<'a, Octs: ?Sized> Clone for QuestionSection<'a, Octs> {
fn clone(&self) -> Self {
QuestionSection {
parser: self.parser,
count: self.count,
}
*self
}
}

Expand Down Expand Up @@ -986,11 +983,7 @@ impl<'a, Octs: Octets + ?Sized> RecordSection<'a, Octs> {

impl<'a, Octs: ?Sized> Clone for RecordSection<'a, Octs> {
fn clone(&self) -> Self {
RecordSection {
parser: self.parser,
section: self.section,
count: self.count,
}
*self
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/base/name/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,7 @@ impl PartialOrd for Label {
///
/// [RFC 4034]: https://tools.ietf.org/html/rfc4034
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.as_slice()
.iter()
.map(u8::to_ascii_lowercase)
.partial_cmp(other.as_slice().iter().map(u8::to_ascii_lowercase))
Some(self.cmp(other))
}
}

Expand Down
26 changes: 17 additions & 9 deletions src/base/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,22 +1491,30 @@ impl Into<Duration> for Ttl {
#[cfg(test)]
mod test {
#[test]
#[cfg(features = "bytes")]
#[cfg(feature = "bytes")]
fn ds_octets_into() {
use crate::base::iana::{DigestAlg, Rtype, SecAlg};
use crate::name::Dname;
use crate::octets::OctetsInto;
use super::*;
use crate::base::iana::{DigestAlg, SecAlg};
use crate::base::name::Dname;
use crate::rdata::Ds;
use bytes::Bytes;
use octseq::octets::OctetsInto;

let ds: Record<Dname<&[u8]>, Ds<&[u8]>> = Record::new(
"a.example".parse().unwrap(),
Dname::from_octets(b"\x01a\x07example\0".as_ref()).unwrap(),
Class::In,
86400,
Ds::new(12, SecAlg::RsaSha256, b"something"),
Ttl::from_secs(86400),
Ds::new(
12,
SecAlg::RsaSha256,
DigestAlg::Sha256,
b"something".as_ref(),
)
.unwrap(),
);
let ds_bytes: Record<Dname<Bytes>, Ds<Bytes>> =
ds.octets_into().unwrap();
ds.clone().octets_into();
assert_eq!(ds.owner(), ds_bytes.owner());
asswer_eq!(ds.data().digest(), ds_bytes.data().digest());
assert_eq!(ds.data().digest(), ds_bytes.data().digest());
}
}

0 comments on commit 8ec0840

Please sign in to comment.