Skip to main content

Candidate

Struct Candidate 

Source
pub struct Candidate {
    pub uri: String,
    pub kind: String,
    pub title: Option<String>,
    pub tier: Tier,
    pub relevance: f64,
    pub depth: usize,
    pub discovered_by: Vec<Discovery>,
    pub object: Option<usize>,
    pub path: Option<String>,
    pub status: Option<String>,
    pub facts: BTreeMap<String, String>,
}
Expand description

One thing the compiler reached, before any budget was spent on it. The compiler folds every path that reached the same identifier into one of these, which is where deduplication happens: the Candidate is the unit, and discovered_by is the evidence of how many ways there were to find it.

The three scalar fields are folded rather than overwritten as paths arrive, and each keeps the best value any path gave: the highest relevance, the shortest depth, and the strongest tier. Strongest means lowest, because Tier is ordered by authority — so a thing reached once as a seed and again three hops out along a weak edge is still a Task-tier entry at relevance 1 and depth 0. Nothing a later path says can demote it.

object and path are the two ways a candidate can have a body: object indexes into the index’s own objects, and path names a file the layer pointed at without indexing. Both can be absent, for something the layer names and this repository does not hold.

use std::collections::BTreeMap;

use majordomus_cli::devcontext::select::Candidate;
use majordomus_cli::devcontext::{Discovery, Selector, Tier};

let way = |selector: Selector, depth: usize, confidence: f64| Discovery {
    selector,
    reason: "for the sake of the example".into(),
    via: None,
    edge: None,
    depth,
    confidence,
    weight: 1.0,
};

// one thing, found twice: named in the request, and again by matching the intent
let c = Candidate {
    uri: "majordomus://adr/0052".into(),
    kind: "adr".into(),
    title: Some("The episode is the boundary".into()),
    tier: Tier::Task,
    relevance: 1.0,
    depth: 0,
    discovered_by: vec![
        way(Selector::Seed, 0, 1.0),
        way(Selector::IntentMatch, 2, 0.4),
    ],
    object: None,
    path: None,
    status: None,
    facts: BTreeMap::new(),
};

// two recorded paths is the fact worth keeping, not something to hide
assert_eq!(c.discovered_by.len(), 2);
// and the entry is trusted as far as its *best* path, not averaged down by its worst
assert_eq!(c.confidence(), 1.0);

Fields§

§uri: String

The canonical identifier.

§kind: String

The kind, as the layer declared it.

§title: Option<String>

The title, when there is one.

§tier: Tier

The tier its cost comes out of.

§relevance: f64

The best relevance any path gave it.

§depth: usize

The shortest depth any path reached it at.

§discovered_by: Vec<Discovery>

Every path that reached it.

§object: Option<usize>

The object, when the index holds one under this identifier.

§path: Option<String>

The file the thing lives in, when it is not an object of the index.

§status: Option<String>

The status word the object declares.

§facts: BTreeMap<String, String>

Facts worth carrying.

Implementations§

Source§

impl Candidate

Source

pub fn confidence(&self) -> f64

The confidence of the most trusted path that reached it: the maximum, not the mean.

Averaging would be wrong in a way that matters. Confidence here is about the provenance of the selection — 1.0 when the repository declared the path, less when the compiler inferred it from words — and a thing the layer explicitly declares does not become less certain because a weaker guess also found it. Finding more ways to something can only raise this number.

A candidate with no recorded path is 0.0 rather than an error, which is also right: nothing vouches for it.

use std::collections::BTreeMap;

use majordomus_cli::devcontext::select::Candidate;
use majordomus_cli::devcontext::{Discovery, Selector, Tier};

let mut c = Candidate {
    uri: "majordomus://rule/project.x@1".into(),
    kind: "rule".into(),
    title: None,
    tier: Tier::Governance,
    relevance: 0.6,
    depth: 1,
    discovered_by: Vec::new(),
    object: None,
    path: None,
    status: None,
    facts: BTreeMap::new(),
};

// nothing vouches for it yet
assert_eq!(c.confidence(), 0.0);

// an inferred path: the words of the intent occurred in its own words
c.discovered_by.push(Discovery {
    selector: Selector::IntentMatch,
    reason: "the intent's words occur in it".into(),
    via: None,
    edge: None,
    depth: 1,
    confidence: 0.4,
    weight: 0.5,
});
assert_eq!(c.confidence(), 0.4);

// and then a declared one, which the guess cannot dilute
c.discovered_by.push(Discovery {
    selector: Selector::Governance,
    reason: "a rule the layer applies to everything".into(),
    via: None,
    edge: None,
    depth: 0,
    confidence: 1.0,
    weight: 1.0,
});
assert_eq!(c.confidence(), 1.0, "the best path decides, never the average");

Trait Implementations§

Source§

impl Clone for Candidate

Source§

fn clone(&self) -> Candidate

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 Candidate

Source§

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

Formats the value using the given formatter. Read more

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> DynClone for T
where T: Clone,

Source§

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

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