Skip to content

Commit

Permalink
fix various clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanbk authored and LeeSmet committed Dec 26, 2024
1 parent 74719ba commit 78dcb1a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion mycelium-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<'de> Deserialize<'de> for Metric {
{
struct MetricVisitor;

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

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
8 changes: 4 additions & 4 deletions mycelium/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Serialize for PublicKey {
}

struct PublicKeyVisitor;
impl<'de> Visitor<'de> for PublicKeyVisitor {
impl Visitor<'_> for PublicKeyVisitor {
type Value = PublicKey;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -336,23 +336,23 @@ impl Deref for PacketBuffer {
}
}

impl<'a> Deref for PacketBufferHeader<'a> {
impl Deref for PacketBufferHeader<'_> {
type Target = [u8; DATA_HEADER_SIZE];

fn deref(&self) -> &Self::Target {
self.data
}
}

impl<'a> Deref for PacketBufferHeaderMut<'a> {
impl Deref for PacketBufferHeaderMut<'_> {
type Target = [u8; DATA_HEADER_SIZE];

fn deref(&self) -> &Self::Target {
self.data
}
}

impl<'a> DerefMut for PacketBufferHeaderMut<'a> {
impl DerefMut for PacketBufferHeaderMut<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.data
}
Expand Down
21 changes: 9 additions & 12 deletions mycelium/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ where
}
message.state = TransmissionState::InProgress;
// Transform message into chunks.
let mut chunks =
Vec::with_capacity((message.len + AVERAGE_CHUNK_SIZE - 1) / AVERAGE_CHUNK_SIZE);
let mut chunks = Vec::with_capacity(message.len.div_ceil(AVERAGE_CHUNK_SIZE));
for (chunk_idx, data_chunk) in
message.msg.data.chunks(AVERAGE_CHUNK_SIZE).enumerate()
{
Expand Down Expand Up @@ -382,8 +381,7 @@ where
// Otherwise unilaterally reset the state. The message id space is large enough to
// avoid accidental collisions.
let mi = MessageInit::new(mp);
let expected_chunks =
(mi.length() as usize + AVERAGE_CHUNK_SIZE - 1) / AVERAGE_CHUNK_SIZE;
let expected_chunks = (mi.length() as usize).div_ceil(AVERAGE_CHUNK_SIZE);
let chunks = vec![None; expected_chunks];
let message = ReceivedMessageInfo {
id: message_id,
Expand Down Expand Up @@ -418,8 +416,7 @@ where
return;
}
// Check max chunk idx.
let max_chunk_idx =
((message.len + MINIMUM_CHUNK_SIZE - 1) / MINIMUM_CHUNK_SIZE) - 1;
let max_chunk_idx = message.len.div_ceil(MINIMUM_CHUNK_SIZE);
if mc.chunk_idx() > max_chunk_idx {
debug!("Dropping CHUNK because index is too high");
return;
Expand Down Expand Up @@ -1132,7 +1129,7 @@ impl Serialize for MessageId {

struct MessageIdVisitor;

impl<'de> Visitor<'de> for MessageIdVisitor {
impl Visitor<'_> for MessageIdVisitor {
type Value = MessageId;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -1234,7 +1231,7 @@ struct Flags<'a> {
_marker: PhantomData<&'a MessagePacketHeader<'a>>,
}

impl<'a> Flags<'a> {
impl Flags<'_> {
/// Check if the MESSAGE_INIT flag is set on the header.
fn init(&self) -> bool {
self.flags & FLAG_MESSAGE_INIT != 0
Expand Down Expand Up @@ -1334,7 +1331,7 @@ impl FlagsMut<'_, '_> {
// - 8 bytes message id
// - 2 bytes flags
// - 2 bytes reserved
impl<'a> MessagePacketHeader<'a> {
impl MessagePacketHeader<'_> {
/// Get the [`MessageId`] from the buffer.
fn message_id(&self) -> MessageId {
MessageId(
Expand Down Expand Up @@ -1400,23 +1397,23 @@ impl<'a> MessagePacketHeaderMut<'a> {
}
}

impl<'a> Deref for MessagePacketHeader<'a> {
impl Deref for MessagePacketHeader<'_> {
type Target = [u8; MESSAGE_HEADER_SIZE];

fn deref(&self) -> &Self::Target {
self.header
}
}

impl<'a> Deref for MessagePacketHeaderMut<'a> {
impl Deref for MessagePacketHeaderMut<'_> {
type Target = [u8; MESSAGE_HEADER_SIZE];

fn deref(&self) -> &Self::Target {
self.header
}
}

impl<'a> DerefMut for MessagePacketHeaderMut<'a> {
impl DerefMut for MessagePacketHeaderMut<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.header
}
Expand Down
2 changes: 1 addition & 1 deletion mycelium/src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Add<&Metric> for Metric {
}
}

impl<'a> Add<Metric> for &'a Metric {
impl Add<Metric> for &Metric {
type Output = Metric;

fn add(self, rhs: Metric) -> Self::Output {
Expand Down
4 changes: 2 additions & 2 deletions mycelium/src/routing_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,13 @@ pub struct RoutingTableReadGuard<'a> {
guard: left_right::ReadGuard<'a, RoutingTableInner>,
}

impl<'a> RoutingTableReadGuard<'a> {
impl RoutingTableReadGuard<'_> {
pub fn iter(&self) -> RoutingTableIter {
RoutingTableIter::new(self.guard.table.iter())
}
}

impl<'a> WriteGuard<'a> {
impl WriteGuard<'_> {
/// Loads the current [`RouteList`].
#[inline]
pub fn routes(&self) -> RouteListReadGuard {
Expand Down
2 changes: 1 addition & 1 deletion mycelium/src/routing_table/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a> RoutingTableIter<'a> {
}
}

impl<'a> Iterator for RoutingTableIter<'a> {
impl Iterator for RoutingTableIter<'_> {
type Item = (Subnet, RouteListReadGuard);

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion mycelium/src/routing_table/iter_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct RoutingTableIterMutEntry<'a, 'b> {
cancellation_token: CancellationToken,
}

impl<'a, 'b> RoutingTableIterMutEntry<'a, 'b> {
impl RoutingTableIterMutEntry<'_, '_> {
pub fn update_routes<F: FnMut(&mut RouteList, &mpsc::Sender<RouteKey>, &CancellationToken)>(
&mut self,
mut op: F,
Expand Down

0 comments on commit 78dcb1a

Please sign in to comment.