Skip to main content

Resolver

Struct Resolver 

Source
pub struct Resolver;
Expand description

Resolves one typed requirement from the provisions declared for it.

Implementations§

Source§

impl Resolver

Source

pub fn resolve<'value, C: Capability>( required_by: ModuleId, provisions: &[Provision<'value, C>], selected: Option<ModuleId>, ) -> Result<&'value C::Value, CompositionError>

Resolves a unique provision, or the provision named by selected.

Registration order never selects a winner. Multiple candidates without explicit selection produce a structured ambiguity error. No global registry, runtime type map, or allocation is needed on the success path.

Examples found in repository?
examples/02-resolution.rs (line 54)
48fn main() -> Result<(), Box<dyn std::error::Error>> {
49    let system_clock = WallClock;
50    let only_system_clock = [Provision::<ClockCapability>::new(
51        SYSTEM_CLOCK,
52        &system_clock as &dyn Clock,
53    )];
54    let clock = Resolver::resolve::<ClockCapability>(GREETER, &only_system_clock, None)?;
55    println!("{}", Greeter::new(clock).greet("world"));
56
57    let test_clock = FixedClock(UNIX_EPOCH + Duration::from_secs(42));
58    let both_clocks = [
59        Provision::<ClockCapability>::new(SYSTEM_CLOCK, &system_clock as &dyn Clock),
60        Provision::<ClockCapability>::new(TEST_CLOCK, &test_clock as &dyn Clock),
61    ];
62    let clock = Resolver::resolve::<ClockCapability>(GREETER, &both_clocks, Some(TEST_CLOCK))?;
63    println!("{}", Greeter::new(clock).greet("Ada"));
64    Ok(())
65}
Source

pub fn resolve_optional<'value, C: Capability>( required_by: ModuleId, provisions: &[Provision<'value, C>], ) -> Result<Option<&'value C::Value>, CompositionError>

Resolves an optional requirement without installing a default provider. Zero candidates returns Ok(None), one returns its value, and multiple candidates remain ambiguous.

Source

pub fn resolve_many<'value, C: Capability>( provisions: &[Provision<'value, C>], ) -> Vec<Provision<'value, C>>

Returns every provider for a many-valued requirement.

Results are sorted by module identity for stable inspection only. This order does not define provider execution or dependency order.

Source

pub fn resolve_qualified<'value, C: Capability, Q: Qualifier>( required_by: ModuleId, provisions: &[QualifiedProvision<'value, C, Q>], selected: Option<ModuleId>, ) -> Result<&'value C::Value, CompositionError>

Resolves a provision for one typed qualifier, excluding other qualifiers from candidate counting and diagnostics.

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.