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: StringTHRESHOLD_KEY, older_than when the caller named one, or absent.
Implementations§
Source§impl Threshold
impl Threshold
Sourcepub fn resolve(
declared: Option<&str>,
older_than: Option<&str>,
) -> Result<Threshold, String>
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());Sourcepub fn declared_at(
root: &Path,
older_than: Option<&str>,
) -> Result<Self, String>
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<'de> Deserialize<'de> for Threshold
impl<'de> Deserialize<'de> for Threshold
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Threshold
Source§impl JsonSchema for Threshold
impl JsonSchema for Threshold
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreimpl StructuralPartialEq for Threshold
Auto Trait Implementations§
impl Freeze for Threshold
impl RefUnwindSafe for Threshold
impl Send for Threshold
impl Sync for Threshold
impl Unpin for Threshold
impl UnsafeUnpin for Threshold
impl UnwindSafe for Threshold
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
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> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.