pub struct TermTracker { /* private fields */ }Expand description
Tracks the current term and votes for leader election
Implementations§
Source§impl TermTracker
impl TermTracker
Sourcepub fn current_term(&self) -> u64
pub fn current_term(&self) -> u64
Return the current term.
Sourcepub fn advance_term(&mut self, new_term: u64) -> bool
pub fn advance_term(&mut self, new_term: u64) -> bool
Advance to a new term, clearing the vote.
Returns true if the term was actually advanced.
Sourcepub fn grant_vote(&mut self, candidate_id: impl Into<String>) -> bool
pub fn grant_vote(&mut self, candidate_id: impl Into<String>) -> bool
Attempt to cast a vote for candidate_id in the current term.
Returns true if the vote was granted (can only vote once per term).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TermTracker
impl RefUnwindSafe for TermTracker
impl Send for TermTracker
impl Sync for TermTracker
impl Unpin for TermTracker
impl UnsafeUnpin for TermTracker
impl UnwindSafe for TermTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request