diff --git a/openraft/src/core/raft_core.rs b/openraft/src/core/raft_core.rs index 230815e85..08a6001b9 100644 --- a/openraft/src/core/raft_core.rs +++ b/openraft/src/core/raft_core.rs @@ -752,10 +752,7 @@ where } pub(crate) fn get_leader_node(&self, leader_id: Option) -> Option { - let leader_id = match leader_id { - None => return None, - Some(x) => x, - }; + let leader_id = leader_id?; self.engine.state.membership_state.effective().get_node(&leader_id).cloned() } @@ -1679,7 +1676,7 @@ where N: RaftNetworkFactory, LS: RaftLogStorage, { - async fn run_command<'e>(&mut self, cmd: Command) -> Result>, StorageError> { + async fn run_command(&mut self, cmd: Command) -> Result>, StorageError> { // tracing::debug!("RAFT_event id={:<2} trycmd: {}", self.id, cmd); let condition = cmd.condition(); diff --git a/openraft/src/display_ext/display_btreemap_opt_value.rs b/openraft/src/display_ext/display_btreemap_opt_value.rs index e7e353e5f..b56a1c14c 100644 --- a/openraft/src/display_ext/display_btreemap_opt_value.rs +++ b/openraft/src/display_ext/display_btreemap_opt_value.rs @@ -11,7 +11,7 @@ use super::DisplayOption; /// For how to format the `opt_value`, see [`DisplayOption`]. pub(crate) struct DisplayBTreeMapOptValue<'a, K: fmt::Display, V: fmt::Display>(pub &'a BTreeMap>); -impl<'a, K: fmt::Display, V: fmt::Display> fmt::Display for DisplayBTreeMapOptValue<'a, K, V> { +impl fmt::Display for DisplayBTreeMapOptValue<'_, K, V> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let len = self.0.len(); for (idx, (key, value)) in self.0.iter().enumerate() { diff --git a/openraft/src/display_ext/display_instant.rs b/openraft/src/display_ext/display_instant.rs index 7e8a7fff9..67515896d 100644 --- a/openraft/src/display_ext/display_instant.rs +++ b/openraft/src/display_ext/display_instant.rs @@ -36,7 +36,7 @@ impl<'a, T, const SIMPLE: bool, const LOCAL: bool> DisplayInstant<'a, T, SIMPLE, } } -impl<'a, T, const SIMPLE: bool, const LOCAL: bool> fmt::Display for DisplayInstant<'a, T, SIMPLE, LOCAL> +impl fmt::Display for DisplayInstant<'_, T, SIMPLE, LOCAL> where T: Instant { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/openraft/src/display_ext/display_option.rs b/openraft/src/display_ext/display_option.rs index 76a821305..bf84e692e 100644 --- a/openraft/src/display_ext/display_option.rs +++ b/openraft/src/display_ext/display_option.rs @@ -6,7 +6,7 @@ use std::fmt; /// implementation for T. pub(crate) struct DisplayOption<'a, T: fmt::Display>(pub &'a Option); -impl<'a, T: fmt::Display> fmt::Display for DisplayOption<'a, T> { +impl fmt::Display for DisplayOption<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.0 { None => { diff --git a/openraft/src/display_ext/display_result.rs b/openraft/src/display_ext/display_result.rs index ed769c383..7db7690f1 100644 --- a/openraft/src/display_ext/display_result.rs +++ b/openraft/src/display_ext/display_result.rs @@ -5,7 +5,7 @@ use std::fmt; /// It outputs `"Ok(...)"` or `"Err(...)"`. pub(crate) struct DisplayResult<'a, T: fmt::Display, E: fmt::Display>(pub &'a Result); -impl<'a, T, E> fmt::Display for DisplayResult<'a, T, E> +impl fmt::Display for DisplayResult<'_, T, E> where T: fmt::Display, E: fmt::Display, diff --git a/openraft/src/display_ext/display_slice.rs b/openraft/src/display_ext/display_slice.rs index cfb8538e4..74d8b33f3 100644 --- a/openraft/src/display_ext/display_slice.rs +++ b/openraft/src/display_ext/display_slice.rs @@ -6,7 +6,7 @@ use std::fmt; /// - `DisplaySlice(&[1,2,3,4,5,6])` outputs: `"[1,2,3,4,...,6]"`. pub(crate) struct DisplaySlice<'a, T: fmt::Display, const MAX: usize = 5>(pub &'a [T]); -impl<'a, T: fmt::Display, const MAX: usize> fmt::Display for DisplaySlice<'a, T, MAX> { +impl fmt::Display for DisplaySlice<'_, T, MAX> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let slice = self.0; let len = slice.len(); diff --git a/openraft/src/docs/faq/mod.rs b/openraft/src/docs/faq/mod.rs index 7eba4e344..ea5f94237 100644 --- a/openraft/src/docs/faq/mod.rs +++ b/openraft/src/docs/faq/mod.rs @@ -1,4 +1,3 @@ //! # FAQ #![doc = include_str!("faq-toc.md")] - #![doc = include_str!("faq.md")] diff --git a/openraft/src/docs/mod.rs b/openraft/src/docs/mod.rs index 33ff577fe..381762298 100644 --- a/openraft/src/docs/mod.rs +++ b/openraft/src/docs/mod.rs @@ -1,9 +1,6 @@ #![allow(rustdoc::redundant_explicit_links)] #![doc = include_str!("docs.md")] -#[rustfmt::skip] - - pub mod faq; pub mod getting_started; diff --git a/openraft/src/engine/handler/following_handler/mod.rs b/openraft/src/engine/handler/following_handler/mod.rs index 9fba6b744..1a0a9d4bc 100644 --- a/openraft/src/engine/handler/following_handler/mod.rs +++ b/openraft/src/engine/handler/following_handler/mod.rs @@ -52,7 +52,7 @@ where C: RaftTypeConfig pub(crate) output: &'x mut EngineOutput, } -impl<'x, C> FollowingHandler<'x, C> +impl FollowingHandler<'_, C> where C: RaftTypeConfig { /// Append entries to follower/learner. diff --git a/openraft/src/engine/handler/leader_handler/mod.rs b/openraft/src/engine/handler/leader_handler/mod.rs index 2fca36c73..85563ebe4 100644 --- a/openraft/src/engine/handler/leader_handler/mod.rs +++ b/openraft/src/engine/handler/leader_handler/mod.rs @@ -37,7 +37,7 @@ where C: RaftTypeConfig pub(crate) output: &'x mut EngineOutput, } -impl<'x, C> LeaderHandler<'x, C> +impl LeaderHandler<'_, C> where C: RaftTypeConfig { /// Append new log entries by a leader. diff --git a/openraft/src/engine/handler/log_handler/mod.rs b/openraft/src/engine/handler/log_handler/mod.rs index f72101a64..bb3d67ec2 100644 --- a/openraft/src/engine/handler/log_handler/mod.rs +++ b/openraft/src/engine/handler/log_handler/mod.rs @@ -22,7 +22,7 @@ where C: RaftTypeConfig pub(crate) output: &'x mut EngineOutput, } -impl<'x, C> LogHandler<'x, C> +impl LogHandler<'_, C> where C: RaftTypeConfig { /// Purge log entries upto `RaftState.purge_upto()`, inclusive. diff --git a/openraft/src/engine/handler/replication_handler/mod.rs b/openraft/src/engine/handler/replication_handler/mod.rs index 75b9012d5..6cce15526 100644 --- a/openraft/src/engine/handler/replication_handler/mod.rs +++ b/openraft/src/engine/handler/replication_handler/mod.rs @@ -50,7 +50,7 @@ where C: RaftTypeConfig pub(crate) output: &'x mut EngineOutput, } -impl<'x, C> ReplicationHandler<'x, C> +impl ReplicationHandler<'_, C> where C: RaftTypeConfig { /// Append a new membership and update related state such as replication streams. diff --git a/openraft/src/engine/handler/server_state_handler/mod.rs b/openraft/src/engine/handler/server_state_handler/mod.rs index 9b0603336..923e3596f 100644 --- a/openraft/src/engine/handler/server_state_handler/mod.rs +++ b/openraft/src/engine/handler/server_state_handler/mod.rs @@ -14,7 +14,7 @@ where C: RaftTypeConfig pub(crate) state: &'st mut RaftState, } -impl<'st, C> ServerStateHandler<'st, C> +impl ServerStateHandler<'_, C> where C: RaftTypeConfig { /// Re-calculate the server-state, if it changed, update the `server_state` field and dispatch diff --git a/openraft/src/engine/handler/snapshot_handler/mod.rs b/openraft/src/engine/handler/snapshot_handler/mod.rs index 78700a58d..9aecfbf59 100644 --- a/openraft/src/engine/handler/snapshot_handler/mod.rs +++ b/openraft/src/engine/handler/snapshot_handler/mod.rs @@ -22,7 +22,7 @@ where C: RaftTypeConfig pub(crate) output: &'out mut EngineOutput, } -impl<'st, 'out, C> SnapshotHandler<'st, 'out, C> +impl SnapshotHandler<'_, '_, C> where C: RaftTypeConfig { /// Trigger building snapshot if there is no pending building job. diff --git a/openraft/src/engine/handler/vote_handler/mod.rs b/openraft/src/engine/handler/vote_handler/mod.rs index d54bc1dd1..7dd55b954 100644 --- a/openraft/src/engine/handler/vote_handler/mod.rs +++ b/openraft/src/engine/handler/vote_handler/mod.rs @@ -49,7 +49,7 @@ where C: RaftTypeConfig pub(crate) candidate: &'st mut CandidateState, } -impl<'st, C> VoteHandler<'st, C> +impl VoteHandler<'_, C> where C: RaftTypeConfig { /// Validate and accept the input `vote` and send result via `tx`. diff --git a/openraft/src/error/invalid_sm.rs b/openraft/src/error/invalid_sm.rs index 9beca1682..60704476e 100644 --- a/openraft/src/error/invalid_sm.rs +++ b/openraft/src/error/invalid_sm.rs @@ -4,7 +4,6 @@ It may have used a different type \ of state machine from the one in RaftCore (`{actual_type}`)" )] - pub struct InvalidStateMachineType { pub actual_type: &'static str, } diff --git a/openraft/src/metrics/metric_display.rs b/openraft/src/metrics/metric_display.rs index f27585474..8b4bec132 100644 --- a/openraft/src/metrics/metric_display.rs +++ b/openraft/src/metrics/metric_display.rs @@ -12,7 +12,7 @@ where C: RaftTypeConfig pub(crate) metric: &'a Metric, } -impl<'a, C> fmt::Display for MetricDisplay<'a, C> +impl fmt::Display for MetricDisplay<'_, C> where C: RaftTypeConfig { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { diff --git a/openraft/src/metrics/serde_instant.rs b/openraft/src/metrics/serde_instant.rs index 117e0a629..e87a61281 100644 --- a/openraft/src/metrics/serde_instant.rs +++ b/openraft/src/metrics/serde_instant.rs @@ -112,7 +112,7 @@ mod serde_impl { where D: Deserializer<'de> { struct InstantVisitor(PhantomData); - impl<'de, II: Instant> Visitor<'de> for InstantVisitor { + impl Visitor<'_> for InstantVisitor { type Value = SerdeInstant; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/openraft/src/progress/mod.rs b/openraft/src/progress/mod.rs index 693b3bcfc..0cde76d91 100644 --- a/openraft/src/progress/mod.rs +++ b/openraft/src/progress/mod.rs @@ -176,7 +176,7 @@ where f: Fmt, } -impl<'a, ID, V, P, QS, Fmt> Display for DisplayVecProgress<'a, ID, V, P, QS, Fmt> +impl Display for DisplayVecProgress<'_, ID, V, P, QS, Fmt> where ID: PartialEq + 'static, V: Borrow

, diff --git a/openraft/src/quorum/joint.rs b/openraft/src/quorum/joint.rs index 9488f5efd..c2b4778f3 100644 --- a/openraft/src/quorum/joint.rs +++ b/openraft/src/quorum/joint.rs @@ -46,7 +46,7 @@ where } /// Implement QuorumSet for `Joint<.., &[QS]>` -impl<'d, ID, QS> QuorumSet for Joint +impl QuorumSet for Joint where ID: PartialOrd + Ord + 'static, QS: QuorumSet, diff --git a/openraft/src/raft_state/io_state/io_progress.rs b/openraft/src/raft_state/io_state/io_progress.rs index 325c97384..a4e2d7e8f 100644 --- a/openraft/src/raft_state/io_state/io_progress.rs +++ b/openraft/src/raft_state/io_state/io_progress.rs @@ -80,7 +80,7 @@ where /// Update the `accept` cursor of the I/O progress. pub(crate) fn accept(&mut self, new_accepted: T) { debug_assert!( - self.accepted.as_ref().map_or(true, |accepted| accepted <= &new_accepted), + self.accepted.as_ref().is_none_or(|accepted| accepted <= &new_accepted), "expect accepted:{} < new_accepted:{}", self.accepted.display(), new_accepted, @@ -92,7 +92,7 @@ where /// Update the `submit` cursor of the I/O progress. pub(crate) fn submit(&mut self, new_submitted: T) { debug_assert!( - self.submitted.as_ref().map_or(true, |submitted| submitted <= &new_submitted), + self.submitted.as_ref().is_none_or(|submitted| submitted <= &new_submitted), "expect submitted:{} < new_submitted:{}", self.submitted.display(), new_submitted, @@ -104,7 +104,7 @@ where /// Update the `flush` cursor of the I/O progress. pub(crate) fn flush(&mut self, new_flushed: T) { debug_assert!( - self.flushed.as_ref().map_or(true, |flushed| flushed <= &new_flushed), + self.flushed.as_ref().is_none_or(|flushed| flushed <= &new_flushed), "expect flushed:{} < new_flushed:{}", self.flushed.display(), new_flushed, diff --git a/openraft/src/raft_state/membership_state/change_handler.rs b/openraft/src/raft_state/membership_state/change_handler.rs index fdece9fb4..299dcc677 100644 --- a/openraft/src/raft_state/membership_state/change_handler.rs +++ b/openraft/src/raft_state/membership_state/change_handler.rs @@ -14,7 +14,7 @@ where C: RaftTypeConfig pub(crate) state: &'m MembershipState, } -impl<'m, C> ChangeHandler<'m, C> +impl ChangeHandler<'_, C> where C: RaftTypeConfig { /// Builds a new membership configuration by applying changes to the current configuration. diff --git a/openraft/src/runtime/mod.rs b/openraft/src/runtime/mod.rs index 1f8e38ac1..564a78b65 100644 --- a/openraft/src/runtime/mod.rs +++ b/openraft/src/runtime/mod.rs @@ -62,5 +62,5 @@ pub(crate) trait RaftRuntime { /// Run a command produced by the engine. /// /// If a command can not be run, i.e., waiting for some event, it will be returned - async fn run_command<'e>(&mut self, cmd: Command) -> Result>, StorageError>; + async fn run_command(&mut self, cmd: Command) -> Result>, StorageError>; } diff --git a/openraft/src/summary.rs b/openraft/src/summary.rs index 3f624e363..6263d1d85 100644 --- a/openraft/src/summary.rs +++ b/openraft/src/summary.rs @@ -39,8 +39,8 @@ where T: fmt::Display } } -impl<'a, T> MessageSummary for &[T] -where T: MessageSummary + 'a +impl MessageSummary for &[T] +where T: MessageSummary { fn summary(&self) -> String { if self.is_empty() { diff --git a/openraft/src/utime.rs b/openraft/src/utime.rs index 36e2d8196..ab12a8da7 100644 --- a/openraft/src/utime.rs +++ b/openraft/src/utime.rs @@ -94,7 +94,7 @@ impl Leased { leased: &'a Leased, } - impl<'a, T, I> fmt::Display for DisplayLeaseInfo<'a, T, I> + impl fmt::Display for DisplayLeaseInfo<'_, T, I> where I: Instant { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/openraft/src/vote/committed.rs b/openraft/src/vote/committed.rs index 9bd07ac7e..02f374258 100644 --- a/openraft/src/vote/committed.rs +++ b/openraft/src/vote/committed.rs @@ -65,7 +65,7 @@ impl RaftVote for CommittedVote where C: RaftTypeConfig { fn from_leader_id(_leader_id: C::LeaderId, _committed: bool) -> Self { - unimplemented!() + unreachable!("CommittedVote should only be built from a Vote") } fn leader_id(&self) -> Option<&LeaderIdOf> { diff --git a/openraft/src/vote/non_committed.rs b/openraft/src/vote/non_committed.rs index 4003d12d1..a9212b2b8 100644 --- a/openraft/src/vote/non_committed.rs +++ b/openraft/src/vote/non_committed.rs @@ -35,7 +35,7 @@ impl RaftVote for NonCommittedVote where C: RaftTypeConfig { fn from_leader_id(_leader_id: C::LeaderId, _committed: bool) -> Self { - unimplemented!() + unreachable!("NonCommittedVote should only be built from a Vote") } fn leader_id(&self) -> Option<&LeaderIdOf> { diff --git a/openraft/src/vote/raft_vote.rs b/openraft/src/vote/raft_vote.rs index f88cf45ec..a5205bf12 100644 --- a/openraft/src/vote/raft_vote.rs +++ b/openraft/src/vote/raft_vote.rs @@ -19,13 +19,13 @@ where C: RaftTypeConfig, Self: OptionalFeatures + Eq + Clone + Debug + Display + Default + 'static, { - /// Create a new vote for the specified leader with optional quorum commitment + /// Create a new vote for the specified leader with optional quorum commitment. fn from_leader_id(leader_id: C::LeaderId, committed: bool) -> Self; - /// Get a reference to this vote's LeaderId([`RaftLeaderId`] implementation) + /// Get a reference to this vote's LeaderId([`RaftLeaderId`] implementation). fn leader_id(&self) -> Option<&C::LeaderId>; - /// Whether this vote has been committed by a quorum + /// Whether this vote has been committed by a quorum. fn is_committed(&self) -> bool; } diff --git a/openraft/src/vote/ref_vote.rs b/openraft/src/vote/ref_vote.rs index ef454ba16..23a72c12f 100644 --- a/openraft/src/vote/ref_vote.rs +++ b/openraft/src/vote/ref_vote.rs @@ -54,7 +54,7 @@ where C: RaftTypeConfig } } -impl<'a, C> std::fmt::Display for RefVote<'a, C> +impl std::fmt::Display for RefVote<'_, C> where C: RaftTypeConfig { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {