Skip to content

Commit

Permalink
Chore: fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Jan 8, 2025
1 parent eeb8fb1 commit d4b4b02
Show file tree
Hide file tree
Showing 29 changed files with 32 additions and 40 deletions.
7 changes: 2 additions & 5 deletions openraft/src/core/raft_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,7 @@ where
}

pub(crate) fn get_leader_node(&self, leader_id: Option<C::NodeId>) -> Option<C::Node> {
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()
}
Expand Down Expand Up @@ -1679,7 +1676,7 @@ where
N: RaftNetworkFactory<C>,
LS: RaftLogStorage<C>,
{
async fn run_command<'e>(&mut self, cmd: Command<C>) -> Result<Option<Command<C>>, StorageError<C>> {
async fn run_command(&mut self, cmd: Command<C>) -> Result<Option<Command<C>>, StorageError<C>> {
// tracing::debug!("RAFT_event id={:<2} trycmd: {}", self.id, cmd);

let condition = cmd.condition();
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/display_ext/display_btreemap_opt_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, Option<V>>);

impl<'a, K: fmt::Display, V: fmt::Display> fmt::Display for DisplayBTreeMapOptValue<'a, K, V> {
impl<K: fmt::Display, V: fmt::Display> 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() {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/display_ext/display_instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, const SIMPLE: bool, const LOCAL: bool> fmt::Display for DisplayInstant<'_, T, SIMPLE, LOCAL>
where T: Instant
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/display_ext/display_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt;
/// implementation for T.
pub(crate) struct DisplayOption<'a, T: fmt::Display>(pub &'a Option<T>);

impl<'a, T: fmt::Display> fmt::Display for DisplayOption<'a, T> {
impl<T: fmt::Display> fmt::Display for DisplayOption<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 {
None => {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/display_ext/display_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, E>);

impl<'a, T, E> fmt::Display for DisplayResult<'a, T, E>
impl<T, E> fmt::Display for DisplayResult<'_, T, E>
where
T: fmt::Display,
E: fmt::Display,
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/display_ext/display_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: fmt::Display, const MAX: usize> fmt::Display for DisplaySlice<'_, T, MAX> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let slice = self.0;
let len = slice.len();
Expand Down
1 change: 0 additions & 1 deletion openraft/src/docs/faq/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! # FAQ
#![doc = include_str!("faq-toc.md")]

#![doc = include_str!("faq.md")]
3 changes: 0 additions & 3 deletions openraft/src/docs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![allow(rustdoc::redundant_explicit_links)]
#![doc = include_str!("docs.md")]

#[rustfmt::skip]


pub mod faq;

pub mod getting_started;
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/following_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where C: RaftTypeConfig
pub(crate) output: &'x mut EngineOutput<C>,
}

impl<'x, C> FollowingHandler<'x, C>
impl<C> FollowingHandler<'_, C>
where C: RaftTypeConfig
{
/// Append entries to follower/learner.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/leader_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where C: RaftTypeConfig
pub(crate) output: &'x mut EngineOutput<C>,
}

impl<'x, C> LeaderHandler<'x, C>
impl<C> LeaderHandler<'_, C>
where C: RaftTypeConfig
{
/// Append new log entries by a leader.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/log_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where C: RaftTypeConfig
pub(crate) output: &'x mut EngineOutput<C>,
}

impl<'x, C> LogHandler<'x, C>
impl<C> LogHandler<'_, C>
where C: RaftTypeConfig
{
/// Purge log entries upto `RaftState.purge_upto()`, inclusive.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/replication_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where C: RaftTypeConfig
pub(crate) output: &'x mut EngineOutput<C>,
}

impl<'x, C> ReplicationHandler<'x, C>
impl<C> ReplicationHandler<'_, C>
where C: RaftTypeConfig
{
/// Append a new membership and update related state such as replication streams.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/server_state_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where C: RaftTypeConfig
pub(crate) state: &'st mut RaftState<C>,
}

impl<'st, C> ServerStateHandler<'st, C>
impl<C> ServerStateHandler<'_, C>
where C: RaftTypeConfig
{
/// Re-calculate the server-state, if it changed, update the `server_state` field and dispatch
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/snapshot_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where C: RaftTypeConfig
pub(crate) output: &'out mut EngineOutput<C>,
}

impl<'st, 'out, C> SnapshotHandler<'st, 'out, C>
impl<C> SnapshotHandler<'_, '_, C>
where C: RaftTypeConfig
{
/// Trigger building snapshot if there is no pending building job.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/engine/handler/vote_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where C: RaftTypeConfig
pub(crate) candidate: &'st mut CandidateState<C>,
}

impl<'st, C> VoteHandler<'st, C>
impl<C> VoteHandler<'_, C>
where C: RaftTypeConfig
{
/// Validate and accept the input `vote` and send result via `tx`.
Expand Down
1 change: 0 additions & 1 deletion openraft/src/error/invalid_sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/metrics/metric_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ where C: RaftTypeConfig
pub(crate) metric: &'a Metric<C>,
}

impl<'a, C> fmt::Display for MetricDisplay<'a, C>
impl<C> fmt::Display for MetricDisplay<'_, C>
where C: RaftTypeConfig
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/metrics/serde_instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod serde_impl {
where D: Deserializer<'de> {
struct InstantVisitor<II: Instant>(PhantomData<II>);

impl<'de, II: Instant> Visitor<'de> for InstantVisitor<II> {
impl<II: Instant> Visitor<'_> for InstantVisitor<II> {
type Value = SerdeInstant<II>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/progress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where
f: Fmt,
}

impl<'a, ID, V, P, QS, Fmt> Display for DisplayVecProgress<'a, ID, V, P, QS, Fmt>
impl<ID, V, P, QS, Fmt> Display for DisplayVecProgress<'_, ID, V, P, QS, Fmt>
where
ID: PartialEq + 'static,
V: Borrow<P>,
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/quorum/joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
}

/// Implement QuorumSet for `Joint<.., &[QS]>`
impl<'d, ID, QS> QuorumSet<ID> for Joint<ID, QS, &'d [QS]>
impl<ID, QS> QuorumSet<ID> for Joint<ID, QS, &[QS]>
where
ID: PartialOrd + Ord + 'static,
QS: QuorumSet<ID>,
Expand Down
6 changes: 3 additions & 3 deletions openraft/src/raft_state/io_state/io_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/raft_state/membership_state/change_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where C: RaftTypeConfig
pub(crate) state: &'m MembershipState<C>,
}

impl<'m, C> ChangeHandler<'m, C>
impl<C> ChangeHandler<'_, C>
where C: RaftTypeConfig
{
/// Builds a new membership configuration by applying changes to the current configuration.
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ pub(crate) trait RaftRuntime<C: RaftTypeConfig> {
/// 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<C>) -> Result<Option<Command<C>>, StorageError<C>>;
async fn run_command(&mut self, cmd: Command<C>) -> Result<Option<Command<C>>, StorageError<C>>;
}
4 changes: 2 additions & 2 deletions openraft/src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ where T: fmt::Display
}
}

impl<'a, T> MessageSummary<T> for &[T]
where T: MessageSummary<T> + 'a
impl<T> MessageSummary<T> for &[T]
where T: MessageSummary<T>
{
fn summary(&self) -> String {
if self.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/utime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<T, I: Instant> Leased<T, I> {
leased: &'a Leased<T, I>,
}

impl<'a, T, I> fmt::Display for DisplayLeaseInfo<'a, T, I>
impl<T, I> fmt::Display for DisplayLeaseInfo<'_, T, I>
where I: Instant
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/vote/committed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<C> RaftVote<C> for CommittedVote<C>
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<C>> {
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/vote/non_committed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<C> RaftVote<C> for NonCommittedVote<C>
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<C>> {
Expand Down
6 changes: 3 additions & 3 deletions openraft/src/vote/raft_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion openraft/src/vote/ref_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where C: RaftTypeConfig
}
}

impl<'a, C> std::fmt::Display for RefVote<'a, C>
impl<C> std::fmt::Display for RefVote<'_, C>
where C: RaftTypeConfig
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Expand Down

0 comments on commit d4b4b02

Please sign in to comment.