Skip to main content

Threshold

Struct Threshold 

Source
pub struct Threshold {
    pub declared: Option<String>,
    pub seconds: Option<u64>,
    pub source: String,
}
Expand description

The age past which uncommitted work nothing holds is abandoned, and where it came from.

It is reported with every reading, so a reader can see what the verdicts were judged against; a threshold nothing declares is carried as absent, not filled in.

use majordomus_cli::worktree::Threshold;
let declared = Threshold::resolve(Some("12h"), None).unwrap();
let wire = serde_json::to_value(&declared).unwrap();
assert_eq!(wire["declared"], "12h");
assert_eq!(wire["seconds"], 43_200);
let absent: Threshold =
    serde_json::from_value(serde_json::json!({"source": "absent"})).unwrap();
assert_eq!((absent.declared, absent.seconds), (None, None), "absent is not a default");

Fields§

§declared: Option<String>

The value as written (12h). Absent when nothing declares one.

§seconds: Option<u64>

The same value, in seconds.

§source: String

THRESHOLD_KEY, older_than when the caller named one, or absent.

Implementations§

Source§

impl Threshold

Source

pub fn resolve( declared: Option<&str>, older_than: Option<&str>, ) -> Result<Threshold, String>

The threshold from the caller’s own value when it gave one, else from the policy’s. A value that is not a duration is refused rather than read as none: a reading that judged against nothing would call no work abandoned and say so with confidence.

use majordomus_cli::worktree::Threshold;
let t = Threshold::resolve(Some("12h"), None).unwrap();
assert_eq!((t.seconds, t.source.as_str()), (Some(43_200), "session.stranded_after"));
let o = Threshold::resolve(Some("12h"), Some("30m")).unwrap();
assert_eq!((o.seconds, o.source.as_str()), (Some(1_800), "older_than"));
let none = Threshold::resolve(None, None).unwrap();
assert_eq!((none.seconds, none.source.as_str()), (None, "absent"));
assert!(Threshold::resolve(Some("soon"), None).is_err());
Source

pub fn declared_at( root: &Path, older_than: Option<&str>, ) -> Result<Self, String>

The threshold a repository declares, or the caller’s own: the policy of the checkout at root is read for THRESHOLD_KEY, and a policy that cannot be read declares nothing.

use majordomus_cli::worktree::Threshold;
// a directory with no layer declares nothing, and the caller's own value still counts
let plain = tempfile::tempdir().unwrap();
let none = Threshold::declared_at(plain.path(), None).unwrap();
assert_eq!((none.seconds, none.source.as_str()), (None, "absent"));
let own = Threshold::declared_at(plain.path(), Some("2h")).unwrap();
assert_eq!((own.seconds, own.source.as_str()), (Some(7_200), "older_than"));
assert!(Threshold::declared_at(plain.path(), Some("later")).is_err());

Trait Implementations§

Source§

impl Clone for Threshold

Source§

fn clone(&self) -> Threshold

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 Debug for Threshold

Source§

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

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

impl<'de> Deserialize<'de> for Threshold

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Threshold

Source§

impl JsonSchema for Threshold

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Threshold

Source§

fn eq(&self, other: &Threshold) -> 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 Serialize for Threshold

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Threshold

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
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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