Skip to content

Commit

Permalink
Clippy-suggested code improvements. (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
partim authored Dec 5, 2024
1 parent e65b697 commit 89640b8
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/crypto/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ impl<'de> serde::Deserialize<'de> for KeyIdentifier {
) -> Result<Self, D::Error> {
struct KeyIdentifierVisitor;

impl<'de> serde::de::Visitor<'de> for KeyIdentifierVisitor {
impl serde::de::Visitor<'_> for KeyIdentifierVisitor {
type Value = KeyIdentifier;

fn expecting(
Expand Down
2 changes: 1 addition & 1 deletion src/repository/aspa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl ProviderAsSet {
#[derive(Clone, Debug)]
pub struct ProviderAsIter<'a>(SliceSource<'a>);

impl<'a> Iterator for ProviderAsIter<'a> {
impl Iterator for ProviderAsIter<'_> {
type Item = Asn;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion src/repository/resources/ipres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<'a> IpBlocksForFamily<'a> {
}
}

impl<'a> fmt::Display for IpBlocksForFamily<'a> {
impl fmt::Display for IpBlocksForFamily<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut blocks_iter = self.blocks.iter();

Expand Down
2 changes: 1 addition & 1 deletion src/repository/roa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl RoaIpAddresses {
#[derive(Clone, Debug)]
pub struct RoaIpAddressIter<'a>(SliceSource<'a>);

impl<'a> Iterator for RoaIpAddressIter<'a> {
impl Iterator for RoaIpAddressIter<'_> {
type Item = RoaIpAddress;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
4 changes: 2 additions & 2 deletions src/repository/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl<'de> serde::Deserialize<'de> for Serial {
) -> Result<Self, D::Error> {
struct SerialVisitor;

impl<'de> serde::de::Visitor<'de> for SerialVisitor {
impl serde::de::Visitor<'_> for SerialVisitor {
type Value = Serial;

fn expecting(
Expand Down Expand Up @@ -665,7 +665,7 @@ impl Eq for SignedData {}
#[derive(Clone, Copy, Debug)]
pub struct SignatureValueContent<'a, Alg>(&'a SignedData<Alg>);

impl<'a, Alg> PrimitiveContent for SignatureValueContent<'a, Alg> {
impl<Alg> PrimitiveContent for SignatureValueContent<'_, Alg> {
const TAG: Tag = Tag::BIT_STRING;

fn encoded_len(&self, _: Mode) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl<'de> serde::Deserialize<'de> for Prefix {
) -> Result<Self, D::Error> {
struct Visitor;

impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = Prefix;

fn expecting(
Expand Down
12 changes: 6 additions & 6 deletions src/resources/asn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Asn {
) -> Result<Self, D::Error> {
struct Visitor;

impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = Asn;

fn expecting(
Expand Down Expand Up @@ -198,7 +198,7 @@ impl Asn {
) -> Result<Self, D::Error> {
struct Visitor;

impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = Asn;

fn expecting(
Expand Down Expand Up @@ -390,7 +390,7 @@ pub struct SmallSetDifference<'a> {
right: Peekable<SmallSetIter<'a>>,
}

impl<'a> Iterator for SmallSetDifference<'a> {
impl Iterator for SmallSetDifference<'_> {
type Item = Asn;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -423,7 +423,7 @@ pub struct SmallSetSymmetricDifference<'a> {
right: Peekable<SmallSetIter<'a>>,
}

impl<'a> Iterator for SmallSetSymmetricDifference<'a> {
impl Iterator for SmallSetSymmetricDifference<'_> {
type Item = Asn;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -455,7 +455,7 @@ pub struct SmallSetIntersection<'a> {
right: Peekable<SmallSetIter<'a>>,
}

impl<'a> Iterator for SmallSetIntersection<'a> {
impl Iterator for SmallSetIntersection<'_> {
type Item = Asn;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -489,7 +489,7 @@ pub struct SmallSetUnion<'a> {
right: Peekable<SmallSetIter<'a>>,
}

impl<'a> Iterator for SmallSetUnion<'a> {
impl Iterator for SmallSetUnion<'_> {
type Item = Asn;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
6 changes: 3 additions & 3 deletions src/rrdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl DeltaElement {
}
}

///--- From
//--- From

impl From<PublishElement> for DeltaElement {
fn from(src: PublishElement) -> Self {
Expand Down Expand Up @@ -1434,7 +1434,7 @@ pub struct ObjectReader<'a>(
base64::XmlDecoderReader<'a>
);

impl<'a> ObjectReader<'a> {
impl ObjectReader<'_> {
/// Processes an element with optional XML PCDATA as object content.
///
/// An object reader is created and passed to the closure `op` for
Expand Down Expand Up @@ -1481,7 +1481,7 @@ impl<'a> ObjectReader<'a> {
}
}

impl<'a> io::Read for ObjectReader<'a> {
impl io::Read for ObjectReader<'_> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
self.0.read(buf)
}
Expand Down
2 changes: 1 addition & 1 deletion src/rtr/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub enum PayloadRef<'a> {

//--- From

impl<'a> From<RouteOrigin> for PayloadRef<'a> {
impl From<RouteOrigin> for PayloadRef<'_> {
fn from(src: RouteOrigin) -> Self {
PayloadRef::Origin(src)
}
Expand Down
42 changes: 18 additions & 24 deletions src/rtr/pdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,6 @@ pub struct Aspa {
#[repr(packed)]
struct AspaFixed {
header: Header,
flags: u8,
afi_flags: u8,

#[allow(dead_code)]
provider_count: u16,
customer: u32,
}

Expand All @@ -818,10 +813,11 @@ impl Aspa {
).expect("ASPA RTR PDU size overflow");
Aspa {
fixed: AspaFixed {
header: Header::new(version, Self::PDU, 0, len),
flags,
afi_flags: 0,
provider_count: providers.asn_count().to_be(),
header: Header::new(
version, Self::PDU,
(flags as u16) << 8,
len
),
customer: customer.into_u32().to_be(),
},
providers
Expand All @@ -848,7 +844,7 @@ impl Aspa {
/// The only flag currently used is the least significant bit that is
/// 1 for an announcement and 0 for a withdrawal.
pub fn flags(&self) -> u8 {
self.fixed.flags
(self.fixed.header.session >> 8) as u8
}

/// Returns the customer ASN.
Expand Down Expand Up @@ -899,7 +895,15 @@ impl Aspa {
let provider_len = match
header.pdu_len()?.checked_sub(mem::size_of::<AspaFixed>())
{
Some(len) => len,
Some(len) => {
if len % 4 != 0 {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"invalid length for ASPA PDU"
))
}
len
}
None => {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
Expand All @@ -909,16 +913,6 @@ impl Aspa {
};
let mut fixed = AspaFixed { header, .. Default::default() };
sock.read_exact(&mut fixed.as_mut()[Header::LEN..]).await?;
if provider_len
!= usize::from(
u16::from_be(fixed.provider_count)
) * mem::size_of::<u32>()
{
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"invalid length for ASPA PDU"
))
}
let providers = ProviderAsns::read(sock, provider_len).await?;
Ok(Aspa { fixed, providers })
}
Expand Down Expand Up @@ -1831,9 +1825,9 @@ mod test {
]).unwrap(),
),
[
2, 11, 0, 0, 0, 0, 0, 24,
1, 0, 0, 2, 0, 1, 0, 15,
0, 1, 0, 13, 0, 1, 0, 14,
2, 11, 1, 0, 0, 0, 0, 20,
0, 1, 0, 15, 0, 1, 0, 13,
0, 1, 0, 14,
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/slurm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ impl<'de> Deserialize<'de> for Base64KeyInfo {
) -> Result<Self, D::Error> {
struct Visitor;

impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = Base64KeyInfo;

fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -736,7 +736,7 @@ mod serde_key_identifier {
) -> Result<KeyIdentifier, D::Error> {
struct Visitor;

impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = KeyIdentifier;

fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
8 changes: 4 additions & 4 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl<'de> Deserialize<'de> for Rsync {
//--- PrimitiveContent

#[cfg(feature = "repository")]
impl<'a> encode::PrimitiveContent for &'a Rsync {
impl encode::PrimitiveContent for &'_ Rsync {
const TAG: Tag = Tag::IA5_STRING;

fn encoded_len(&self, _: Mode) -> usize {
Expand Down Expand Up @@ -779,7 +779,7 @@ impl<'de> Deserialize<'de> for Https {
//--- PrimitiveContent

#[cfg(feature = "repository")]
impl<'a> encode::PrimitiveContent for &'a Https {
impl encode::PrimitiveContent for &'_ Https {
const TAG: Tag = Tag::IA5_STRING;

fn encoded_len(&self, _: Mode) -> usize {
Expand Down Expand Up @@ -871,7 +871,7 @@ impl<V> Default for UriVisitor<V> {
}

#[cfg(feature = "serde")]
impl<'de, V> serde::de::Visitor<'de> for UriVisitor<V>
impl<V> serde::de::Visitor<'_> for UriVisitor<V>
where
V: FromStr + TryFrom<String>,
<V as FromStr>::Err: fmt::Display,
Expand Down Expand Up @@ -980,7 +980,7 @@ mod arbitrary {
}
}

impl<'a> Arbitrary<'a> for super::Https {
impl Arbitrary<'_> for super::Https {
fn arbitrary(u: &mut Unstructured) -> arbitrary::Result<Self> {
let mut res = String::from("https://");
append_host(&mut res, u)?;
Expand Down
4 changes: 2 additions & 2 deletions src/util/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'a> SkipWhitespace<'a> {
}
}

impl<'a> io::Read for SkipWhitespace<'a> {
impl io::Read for SkipWhitespace<'_> {
fn read(&mut self, mut buf: &mut[u8]) -> Result<usize, io::Error> {
let mut res = 0;

Expand Down Expand Up @@ -205,7 +205,7 @@ pub struct XmlDecoderReader<'a>(
>
);

impl<'a> io::Read for XmlDecoderReader<'a> {
impl io::Read for XmlDecoderReader<'_> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
self.0.read(buf)
}
Expand Down
10 changes: 5 additions & 5 deletions src/xml/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl<'n, 'l> Name<'n, 'l> {
}
}

impl<'n, 'l> fmt::Debug for Name<'n, 'l> {
impl fmt::Debug for Name<'_, '_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Name(")?;
if let Some(ns) = self.namespace {
Expand All @@ -381,13 +381,13 @@ impl<'n, 'l> fmt::Debug for Name<'n, 'l> {
}
}

impl<'n, 'l> From<&'l [u8]> for Name<'n, 'l> {
impl<'l> From<&'l [u8]> for Name<'_, 'l> {
fn from(local: &'l [u8]) -> Self {
Name::unqualified(local)
}
}

impl<'n, 'l> From<&'l str> for Name<'n, 'l> {
impl<'l> From<&'l str> for Name<'_, 'l> {
fn from(local: &'l str) -> Self {
Name::unqualified(local.as_bytes())
}
Expand All @@ -412,7 +412,7 @@ impl<'n, 'l> From<(&'n str, &'l str)> for Name<'n, 'l> {
#[derive(Clone)]
pub struct AttrValue<'a>(quick_xml::events::attributes::Attribute<'a>);

impl<'a> AttrValue<'a> {
impl AttrValue<'_> {
pub fn ascii_into<T: str::FromStr>(self) -> Result<T, Error> {
let s = self.0.unescape_value()?;
if !s.is_ascii() {
Expand All @@ -435,7 +435,7 @@ impl<'a> AttrValue<'a> {

pub struct Text<'a>(quick_xml::events::BytesText<'a>);

impl<'a> Text<'a> {
impl Text<'_> {
pub fn to_utf8(&self) -> Result<Cow<str>, Error> {
Ok(self.0.unescape()?)
}
Expand Down
8 changes: 4 additions & 4 deletions src/xml/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'a, W: io::Write> Element<'a, W> {
}
}

impl<'a, W: io::Write> Drop for Element<'a, W> {
impl<W: io::Write> Drop for Element<'_, W> {
fn drop(&mut self) {
if let Err(err) = self.end() {
self.writer.store_error(err)
Expand All @@ -246,7 +246,7 @@ pub struct Content<'a, W> {
writer: &'a mut Writer<W>,
}

impl<'a, W: io::Write> Content<'a, W> {
impl<W: io::Write> Content<'_, W> {
/// Add an element with the given tag.
///
/// This will write the beginning of the tag to the writer and therefore
Expand Down Expand Up @@ -417,8 +417,8 @@ impl<'a, W: io::Write> DisplayText<'a, W> {
}
}

impl<'a, W: io::Write> fmt::Write for DisplayText<'a, W> {
fn write_str(&mut self, s: &str) -> fmt::Result {
impl<W: io::Write> fmt::Write for DisplayText<'_, W> {
fn write_str(&mut self, s: &str) -> fmt::Result {
match self.escape.write_escaped(s.as_bytes(), self.inner) {
Ok(()) => Ok(()),
Err(err) => {
Expand Down

0 comments on commit 89640b8

Please sign in to comment.