Skip to main content

InstanceResolver

Struct InstanceResolver 

Source
pub struct InstanceResolver { /* private fields */ }
Expand description

Instance resolution engine.

Maintains a registry of type-class instances organised by class name. Supports priority-based selection, caching, and backtracking search.

Implementations§

Source§

impl InstanceResolver

Source

pub fn new() -> Self

Create a new instance resolver with default settings.

Source

pub fn with_max_depth(max_depth: usize) -> Self

Create a resolver with a custom search depth.

Source

pub fn register(&mut self, instance: InstanceDecl)

Register an instance.

Source

pub fn register_many( &mut self, instances: impl IntoIterator<Item = InstanceDecl>, )

Register multiple instances at once.

Source

pub fn clear_class(&mut self, class: &Name)

Remove all instances for a given class (useful in testing).

Source

pub fn find_instance( &mut self, class: &Name, ty: &Expr, ) -> Option<&InstanceDecl>

Find an instance for a type class and type.

Returns the highest-priority matching instance, or None. If the cache is enabled, previously found instances are returned immediately.

Source

pub fn resolve(&mut self, class: &Name, ty: &Expr) -> ResolutionResult

Resolve an instance and return the full ResolutionResult.

Unlike find_instance, this method detects ambiguity.

Source

pub fn resolve_or_error( &mut self, class: &Name, ty: &Expr, ) -> Result<Name, InstanceError>

Try to resolve, returning Err with a detailed error on failure.

Source

pub fn get_instances(&self, class: &Name) -> Vec<&InstanceDecl>

Get all instances for a class.

Source

pub fn class_count(&self) -> usize

Return the number of classes registered.

Source

pub fn total_registered(&self) -> usize

Return the total number of instances registered.

Source

pub fn set_max_depth(&mut self, depth: usize)

Set the maximum search depth.

Source

pub fn max_depth(&self) -> usize

Get the maximum search depth.

Source

pub fn set_cache_enabled(&mut self, enabled: bool)

Enable or disable the resolution cache.

Source

pub fn cache_enabled(&self) -> bool

Return whether caching is enabled.

Source

pub fn cache(&self) -> &InstanceCache

Obtain a reference to the resolution cache for diagnostics.

Source

pub fn clear_cache(&mut self)

Clear the resolution cache.

Source

pub fn has_instances_for(&self, class: &Name) -> bool

Check whether any instance is registered for a given class.

Source

pub fn registered_classes(&self) -> Vec<&Name>

Return all class names that have at least one instance.

Trait Implementations§

Source§

impl Default for InstanceResolver

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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 = 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.