This is an automated email from the ASF dual-hosted git repository.

hgruszecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git


The following commit(s) were added to refs/heads/master by this push:
     new 7a7b0eda4 chore(message_bus): enable pedantic and nursery clippy lints 
(#2873)
7a7b0eda4 is described below

commit 7a7b0eda421bfc7214d765665c21d195a1618bab
Author: Hubert Gruszecki <[email protected]>
AuthorDate: Mon Mar 9 10:56:52 2026 +0100

    chore(message_bus): enable pedantic and nursery clippy lints (#2873)
    
    Co-authored-by: Grzegorz Koszyk 
<[email protected]>
---
 core/message_bus/Cargo.toml              |  5 +++++
 core/message_bus/src/cache/connection.rs | 20 +++++++++-----------
 core/message_bus/src/cache/mod.rs        |  2 +-
 core/message_bus/src/lib.rs              |  7 +++++--
 4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/core/message_bus/Cargo.toml b/core/message_bus/Cargo.toml
index b8bcdf15f..fabab64ce 100644
--- a/core/message_bus/Cargo.toml
+++ b/core/message_bus/Cargo.toml
@@ -30,3 +30,8 @@ readme = "../../../README.md"
 [dependencies]
 iggy_common = { workspace = true }
 rand = { workspace = true }
+
+[lints.clippy]
+enum_glob_use = "deny"
+pedantic = "deny"
+nursery = "deny"
diff --git a/core/message_bus/src/cache/connection.rs 
b/core/message_bus/src/cache/connection.rs
index 633dc2280..a52a260f3 100644
--- a/core/message_bus/src/cache/connection.rs
+++ b/core/message_bus/src/cache/connection.rs
@@ -36,17 +36,17 @@ pub trait ShardedState {
 /// Least-loaded allocation strategy for connections
 #[derive(Debug)]
 pub struct LeastLoadedStrategy {
-    total_shards: usize,
+    total_shards: u16,
     connections_per_shard: RefCell<Vec<(u16, usize)>>,
     replica_to_shards: RefCell<HashMap<u8, HashSet<u16>>>,
     rng_seed: u64,
 }
 
 impl LeastLoadedStrategy {
-    pub fn new(total_shards: usize, seed: u64) -> Self {
+    pub fn new(total_shards: u16, seed: u64) -> Self {
         Self {
             total_shards,
-            connections_per_shard: RefCell::new((0..total_shards).map(|s| (s 
as u16, 0)).collect()),
+            connections_per_shard: RefCell::new((0..total_shards).map(|s| (s, 
0)).collect()),
             replica_to_shards: RefCell::new(HashMap::new()),
             rng_seed: seed,
         }
@@ -58,11 +58,11 @@ impl LeastLoadedStrategy {
         replica: u8,
         mut conn_shards: Vec<u16>,
     ) {
-        for shard in &conn_shards {
+        for &shard in &conn_shards {
             mappings.push(ShardAssignment {
                 replica,
-                shard: *shard,
-                conn_shard: *shard,
+                shard,
+                conn_shard: shard,
             });
         }
 
@@ -71,7 +71,6 @@ impl LeastLoadedStrategy {
 
         let mut j = 0;
         for shard in 0..self.total_shards {
-            let shard = shard as u16;
             if conn_shards.contains(&shard) {
                 continue;
             }
@@ -123,7 +122,7 @@ impl AllocationStrategy<ConnectionCache> for 
LeastLoadedStrategy {
 
         let mut connections = Vec::new();
         let mut mappings = Vec::new();
-        let connections_needed = 
self.total_shards.min(MAX_CONNECTIONS_PER_REPLICA);
+        let connections_needed = 
usize::from(self.total_shards).min(MAX_CONNECTIONS_PER_REPLICA);
 
         let mut rng = StdRng::seed_from_u64(self.rng_seed);
         self.connections_per_shard.borrow_mut().shuffle(&mut rng);
@@ -182,7 +181,6 @@ impl AllocationStrategy<ConnectionCache> for 
LeastLoadedStrategy {
         }
 
         for shard in 0..self.total_shards {
-            let shard = shard as u16;
             mappings.push(ConnectionAssignment { replica, shard });
         }
 
@@ -209,7 +207,7 @@ where
     SS: ShardedState,
     A: AllocationStrategy<SS>,
 {
-    pub fn new(strategy: A) -> Self {
+    pub const fn new(strategy: A) -> Self {
         Self {
             strategy,
             _ss: std::marker::PhantomData,
@@ -271,7 +269,7 @@ pub struct ConnectionCache {
 
 impl ConnectionCache {
     pub fn get_connection(&self, replica: u8) -> Option<Rc<TcpSender>> {
-        self.connections.get(&replica).and_then(|opt| opt.clone())
+        self.connections.get(&replica).and_then(Clone::clone)
     }
 
     pub fn get_mapped_shard(&self, replica: u8) -> Option<u16> {
diff --git a/core/message_bus/src/cache/mod.rs 
b/core/message_bus/src/cache/mod.rs
index 29ffaec68..fd239df97 100644
--- a/core/message_bus/src/cache/mod.rs
+++ b/core/message_bus/src/cache/mod.rs
@@ -27,4 +27,4 @@ where
     fn deallocate(&self, entry: SS::Entry) -> Option<SS::Delta>;
 }
 
-pub(crate) mod connection;
+pub mod connection;
diff --git a/core/message_bus/src/lib.rs b/core/message_bus/src/lib.rs
index 027fe9f56..876061bc4 100644
--- a/core/message_bus/src/lib.rs
+++ b/core/message_bus/src/lib.rs
@@ -57,7 +57,8 @@ pub struct IggyMessageBus {
 }
 
 impl IggyMessageBus {
-    pub fn new(total_shards: usize, shard_id: u16, seed: u64) -> Self {
+    #[must_use]
+    pub fn new(total_shards: u16, shard_id: u16, seed: u64) -> Self {
         Self {
             clients: HashMap::new(),
             replicas: ShardedConnections {
@@ -81,6 +82,7 @@ impl IggyMessageBus {
     }
 }
 
+#[allow(clippy::future_not_send)] // Single-threaded runtime (compio), 
Rc/RefCell by design
 impl MessageBus for IggyMessageBus {
     type Client = u128;
     type Replica = u8;
@@ -112,6 +114,7 @@ impl MessageBus for IggyMessageBus {
         client_id: Self::Client,
         _message: Self::Data,
     ) -> Result<(), IggyError> {
+        #[allow(clippy::cast_possible_truncation)] // 
IggyError::ClientNotFound takes u32
         let _sender = self
             .clients
             .get(&client_id)
@@ -127,7 +130,7 @@ impl MessageBus for IggyMessageBus {
         // TODO: Handle lazily creating the connection.
         let _connection = self
             .get_replica_connection(replica)
-            .ok_or(IggyError::ResourceNotFound(format!("Replica {}", 
replica)))?;
+            .ok_or(IggyError::ResourceNotFound(format!("Replica {replica}")))?;
         Ok(())
     }
 }

Reply via email to