Skip to main content

TypeClassRegistry

Struct TypeClassRegistry 

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

The registry that holds all type class and instance declarations.

Implementations§

Source§

impl TypeClassRegistry

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn register_class(&mut self, class: TypeClass)

Register a type class.

Source

pub fn get_class(&self, name: &Name) -> Option<&TypeClass>

Look up a class by name.

Source

pub fn is_class(&self, name: &Name) -> bool

Check whether a name refers to a registered class.

Source

pub fn class_count(&self) -> usize

Number of registered classes.

Source

pub fn class_names(&self) -> impl Iterator<Item = &String>

Iterate over all class names.

Source

pub fn subclasses_of(&self, super_name: &Name) -> Vec<&TypeClass>

Get all classes that extend the given super-class.

Source

pub fn register_instance(&mut self, instance: Instance)

Register an instance.

Source

pub fn find_instances(&self, class: &Name, ty: &Expr) -> Vec<&Instance>

Search for instances of the given class for the given type.

Source

pub fn find_best_instance( &self, class: &Name, ty: &Expr, ) -> InstanceSearchResult

Find the best (highest priority, lowest number) instance.

Source

pub fn instance_count(&self) -> usize

Number of registered instances.

Source

pub fn clear_local_instances(&mut self)

Remove all local instances.

Source

pub fn instances_for_class(&self, class: &Name) -> Vec<&Instance>

Get all instances for a given class, sorted by priority.

Source

pub fn filter_instances<F>(&self, predicate: F) -> Vec<&Instance>
where F: Fn(&Instance) -> bool,

Get instances that match a given type predicate.

Source

pub fn method_projection(&self, class: &Name, method: &Name) -> Option<Expr>

Get the projection expression for a method in a class (method index → projection).

Source

pub fn summary(&self) -> String

Summarize the registry.

Source§

impl TypeClassRegistry

Source

pub fn snapshot(&self) -> RegistrySnapshot

Take a snapshot of the current instance count.

Source

pub fn restore(&mut self, snapshot: RegistrySnapshot)

Restore the registry to a previously taken snapshot (removes instances added after).

Trait Implementations§

Source§

impl Clone for TypeClassRegistry

Source§

fn clone(&self) -> TypeClassRegistry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TypeClassRegistry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TypeClassRegistry

Source§

fn default() -> TypeClassRegistry

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