Skip to main content

Patience

Struct Patience 

Source
pub struct Patience {
    pub cold: Duration,
    pub moved: Duration,
}
Expand description

How long a read waits for a worker before it returns what it has.

use majordomus_cli::capability::readings::Patience;
use std::time::Duration;

// a page waits a minute for a first reading and 50 ms for a moved repository
assert_eq!(Patience::PAGE.cold, Duration::from_secs(60));
assert_eq!(Patience::PAGE.moved, Duration::from_millis(50));
// an exact read waits for as long as it takes
assert_eq!(Patience::WAIT.moved, Duration::MAX);
let brief = Patience { cold: Duration::from_millis(5), moved: Duration::ZERO };
assert!(brief.moved < Patience::PAGE.moved);

Fields§

§cold: Duration

For a source that has never been read in this process.

§moved: Duration

For a source read before the repository last moved.

Implementations§

Source§

impl Patience

Source

pub const WAIT: Patience

Wait for a current reading, however long it takes.

Source

pub const PAGE: Patience

What a page is served with: a first reading is waited for up to a minute, because there is nothing else to show, and a reading the repository has moved past for 50 ms, half of the 100 ms a warm page is allowed (the owner’s UI-performance pack).

Source

pub fn of_process() -> Patience

The patience of this process: PATIENCE_SWITCH when it is set, and otherwise Patience::PAGE. The crate’s own unit tests wait, so that a test which renders a screen asserts on a current reading and never on a timing.

use majordomus_cli::capability::readings::{Patience, PATIENCE_SWITCH};

// what the switch says when it is set and means something, a page's patience otherwise
let set = std::env::var(PATIENCE_SWITCH).ok();
let expected = Patience::parse(set.as_deref()).unwrap_or(Patience::PAGE);
assert_eq!(Patience::of_process(), expected);
Source

pub fn parse(value: Option<&str>) -> Option<Patience>

What a value of PATIENCE_SWITCH means, or None when it means nothing: wait is Patience::WAIT, and a number is that many milliseconds for a repository that has moved, with a first reading waited for no less than a page waits.

use majordomus_cli::capability::readings::Patience;
assert_eq!(Patience::parse(Some("wait")), Some(Patience::WAIT));
let twenty = Patience::parse(Some(" 20 ")).unwrap();
assert_eq!(twenty.moved.as_millis(), 20);
assert_eq!(twenty.cold, Patience::PAGE.cold, "a first reading is still waited for");
assert_eq!(Patience::parse(Some("soon")), None, "not a number and not `wait`");
assert_eq!(Patience::parse(None), None);

Trait Implementations§

Source§

impl Clone for Patience

Source§

fn clone(&self) -> Patience

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Patience

Source§

impl Debug for Patience

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Patience

Source§

impl PartialEq for Patience

Source§

fn eq(&self, other: &Patience) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Patience

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsOut<T> for T
where T: Copy,

§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more