openraft 0.10.2

Advanced Raft consensus
Documentation
mod raft_term_impls;

use std::fmt::Debug;
use std::fmt::Display;

use openraft_macros::since;

use crate::base::OptionalFeatures;

/// Type representing a Raft term number.
///
/// A term is a logical clock in Raft that is used to detect obsolete information,
/// such as old leaders. It must be totally ordered and monotonically increasing.
///
/// Common implementations are provided for standard integer types like `u64`, `u32`, etc.
#[since(
    version = "0.10.2",
    change = "built-in integer implementations panic at exhaustion in all builds"
)]
#[since(version = "0.10.0")]
pub trait RaftTerm
where Self: OptionalFeatures + Ord + Debug + Display + Copy + Default + 'static
{
    /// Returns the next term, which must be strictly greater than `self`.
    ///
    /// # Panics
    ///
    /// The built-in integer implementations panic at the type's maximum value in all
    /// build profiles because no greater term can be represented.
    fn next(&self) -> Self;

    /// Convert to u64 for metrics recording.
    ///
    /// Returns `None` if the term cannot be represented as u64.
    /// Implementers must explicitly choose whether their term type
    /// can be converted to u64 for metrics purposes.
    fn as_u64(&self) -> Option<u64>;
}