pub struct TierRule {
pub tier: Tier,
pub position: usize,
pub meaning: String,
pub kinds: Vec<String>,
}Expand description
One tier, as the policy reports it: its place in the spend order, what it is for, and which kinds of object land in it.
position is 1-based and exists because the wire form has no inherent order a consumer
can rely on — the Tier enum’s Ord is a Rust fact, not a JSON one — so the rank is
made explicit for the readers that are not this crate. kinds is the inverse of
tier_for_kind, published so that a caller can see where a kind will land without
compiling an answer and looking.
use majordomus_cli::devcontext::{policy, tier_for_kind, Tier, TierRule};
use majordomus_cli::synthetic::SyntheticRepository;
let repo = SyntheticRepository::small().unwrap();
let ctx = repo.context().unwrap();
let rules = policy(&ctx).unwrap();
// the first tier spent is the one that is never dropped, at position 1
let first: &TierRule = &rules.tiers[0];
assert_eq!(first.tier, Tier::Task);
assert_eq!(first.position, 1, "1-based, so the order survives serialisation");
// every tier is reported, in the order the budget spends in, and explains itself
assert_eq!(rules.tiers.len(), Tier::ORDER.len());
for (i, r) in rules.tiers.iter().enumerate() {
assert_eq!(r.position, i + 1);
assert_eq!(r.meaning, r.tier.meaning());
}
// and every kind is listed under the tier the classifier puts it in, exactly once —
// so the published table and the function behind it cannot disagree
let mut listed = 0usize;
for r in &rules.tiers {
for kind in &r.kinds {
assert_eq!(tier_for_kind(kind), r.tier, "{kind} is listed under the wrong tier");
listed += 1;
}
}
let mut all: Vec<&str> = rules.tiers.iter().flat_map(|r| &r.kinds).map(String::as_str).collect();
all.sort();
all.dedup();
assert_eq!(all.len(), listed, "a kind is listed under one tier only");Fields§
§tier: TierThe tier.
position: usizeIts position in the order the budget spends in; 1 is spent first.
meaning: StringWhat it is for.
kinds: Vec<String>The kinds of object that land in it.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TierRule
impl<'de> Deserialize<'de> for TierRule
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for TierRule
Source§impl JsonSchema for TierRule
impl JsonSchema for TierRule
Source§fn schema_id() -> Cow<'static, str>
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
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
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 moreimpl StructuralPartialEq for TierRule
Auto Trait Implementations§
impl Freeze for TierRule
impl RefUnwindSafe for TierRule
impl Send for TierRule
impl Sync for TierRule
impl Unpin for TierRule
impl UnsafeUnpin for TierRule
impl UnwindSafe for TierRule
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
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
Compare self to
key and return true if they are equal.