Skip to main content

Selection

Struct Selection 

Source
pub struct Selection {
    pub candidates: BTreeMap<String, Candidate>,
    pub unresolved: Vec<(String, String)>,
    pub diagnostics: Vec<Diagnostic>,
}
Expand description

The candidates a request reaches, and everything the walk learned on the way.

Keyed by canonical identifier, which is what makes structural deduplication a property of the type rather than a step: one identifier cannot be in here twice, so the question “was this reached more than once” is answered by a candidate’s discovered_by and never by scanning for duplicates.

The other two fields are what the walk could not do, and neither is an error. unresolved is a name the layer declares and this repository holds nothing under — a dangling reference, which is a fact about the repository worth reporting. diagnostics is what could not be read. The budget turns both into rows of the answer rather than swallowing them.

use std::collections::BTreeMap;

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

let uri = "majordomus://adr/0052";
let candidate = Candidate {
    uri: uri.into(),
    kind: "adr".into(),
    title: None,
    tier: Tier::Decision,
    relevance: 0.8,
    depth: 1,
    discovered_by: vec![Discovery {
        selector: Selector::Relation,
        reason: "the decision in force over this scope".into(),
        via: Some("majordomus://issue/I0301".into()),
        edge: Some("governed_by".into()),
        depth: 1,
        confidence: 1.0,
        weight: 0.9,
    }],
    object: None,
    path: None,
    status: None,
    facts: BTreeMap::new(),
};

let selection = Selection {
    candidates: BTreeMap::from([(uri.to_string(), candidate)]),
    // a reference the layer declares and nothing answers: reported, not dropped
    unresolved: vec![("majordomus://rule/gone@1".into(), "depends_on".into())],
    diagnostics: Vec::new(),
};

// the identifier is the key, so one thing is one entry however many paths found it
assert_eq!(selection.candidates.len(), 1);
assert_eq!(selection.candidates[uri].discovered_by.len(), 1);
assert!(selection.candidates.contains_key(uri));

// and a dangling reference survives to be reported as one
assert_eq!(selection.unresolved[0].0, "majordomus://rule/gone@1");

Fields§

§candidates: BTreeMap<String, Candidate>

By canonical identifier.

§unresolved: Vec<(String, String)>

Names the layer declares that resolve to nothing this repository holds.

§diagnostics: Vec<Diagnostic>

What could not be read, never an error.

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> 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, 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