pub struct LeaseConfig { /* private fields */ }Expand description
The lease timings of one role.
The three extents are independent of the record layout, so one process can
hold several roles with different timings. Build a value with
LeaseConfig::new, which rejects a set of extents that cannot work, or
take the defaults with LeaseConfig::default.
Implementations§
Source§impl LeaseConfig
impl LeaseConfig
Sourcepub fn new(
duration: Time,
renew_interval: Time,
challenge_stagger: Time,
) -> Result<Self, CoordinationError>
pub fn new( duration: Time, renew_interval: Time, challenge_stagger: Time, ) -> Result<Self, CoordinationError>
Builds a lease policy from three extents.
A caller should set renew_interval to at most a third of duration.
The holder then keeps two more attempts before the deadline. The
constructor accepts a larger value and does not reject it. Ask
LeaseConfig::renews_with_margin which side of that bound a value is
on.
§Errors
Returns CoordinationError::InvalidConfig when duration,
renew_interval, or challenge_stagger is zero, negative, infinite, or
NaN. Returns the same error when renew_interval is equal to or
larger than duration, because the holder then never renews in time.
Sourcepub const fn renew_interval(&self) -> Time
pub const fn renew_interval(&self) -> Time
The gap between two renewals by the holder.
Sourcepub const fn challenge_stagger(&self) -> Time
pub const fn challenge_stagger(&self) -> Time
The extra delay that one rank of succession adds.
Sourcepub fn renews_with_margin(&self) -> bool
pub fn renews_with_margin(&self) -> bool
Reports whether the renew interval leaves the holder two spare attempts.
The renew interval that this crate recommends is at most a third of the lease duration. A configuration outside that bound still works, and the holder then loses the role after fewer missed renewals.
Sourcepub fn challenge_delay_millis(&self, rank: usize) -> i64
pub fn challenge_delay_millis(&self, rank: usize) -> i64
The extra delay in milliseconds that a challenger of rank rank takes.
The value saturates at i64::MAX, so a very large rank does not wrap
the instant that a caller adds it to.
Sourcepub fn grant(
&self,
member: MemberId,
token: FencingToken,
now_millis: i64,
) -> Lease
pub fn grant( &self, member: MemberId, token: FencingToken, now_millis: i64, ) -> Lease
The lease record that a member writes after it mints token.
A renewal writes the same record with the same token and a later
now_millis, so this one function covers a first grant and a renewal.
Sourcepub const fn timing<'lease>(&self, lease: &'lease Lease) -> LeaseTiming<'lease>
pub const fn timing<'lease>(&self, lease: &'lease Lease) -> LeaseTiming<'lease>
The clock questions that this policy answers about lease.
Trait Implementations§
Source§impl Clone for LeaseConfig
impl Clone for LeaseConfig
Source§fn clone(&self) -> LeaseConfig
fn clone(&self) -> LeaseConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for LeaseConfig
Source§impl Debug for LeaseConfig
impl Debug for LeaseConfig
Source§impl Default for LeaseConfig
impl Default for LeaseConfig
Source§impl PartialEq for LeaseConfig
impl PartialEq for LeaseConfig
Source§fn eq(&self, other: &LeaseConfig) -> bool
fn eq(&self, other: &LeaseConfig) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for LeaseConfig
Auto Trait Implementations§
impl Freeze for LeaseConfig
impl RefUnwindSafe for LeaseConfig
impl Send for LeaseConfig
impl Sync for LeaseConfig
impl Unpin for LeaseConfig
impl UnsafeUnpin for LeaseConfig
impl UnwindSafe for LeaseConfig
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);