pub struct Instance {
pub class: Name,
pub ty: Expr,
pub priority: i32,
pub methods: HashMap<String, Expr>,
pub instance_name: Option<Name>,
pub is_local: bool,
}Expand description
An instance of a type class.
For example, instance : Add Nat is an instance of Add for the type Nat.
Fields§
§class: NameThe class this is an instance of.
ty: ExprThe type argument(s) for this instance.
priority: i32Search priority (lower number = searched first).
methods: HashMap<String, Expr>Implementations of each method (method name → expression).
instance_name: Option<Name>Optional name for the instance declaration.
is_local: boolWhether this is a local (hypothetical) instance.
Implementations§
Source§impl Instance
impl Instance
Sourcepub fn new(class: Name, ty: Expr) -> Self
pub fn new(class: Name, ty: Expr) -> Self
Create a new anonymous instance with default priority.
Sourcepub fn with_priority(self, priority: i32) -> Self
pub fn with_priority(self, priority: i32) -> Self
Set the priority.
Sourcepub fn add_method_impl(
&mut self,
method_name: impl Into<String>,
impl_expr: Expr,
)
pub fn add_method_impl( &mut self, method_name: impl Into<String>, impl_expr: Expr, )
Add an implementation for a method.
Sourcepub fn get_method_impl(&self, method_name: &str) -> Option<&Expr>
pub fn get_method_impl(&self, method_name: &str) -> Option<&Expr>
Look up the implementation of a method.
Sourcepub fn implements_all(&self, class: &TypeClass) -> bool
pub fn implements_all(&self, class: &TypeClass) -> bool
Check whether all methods of the given class are implemented.
Sourcepub fn implemented_count(&self) -> usize
pub fn implemented_count(&self) -> usize
Number of implemented methods.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Instance
impl RefUnwindSafe for Instance
impl Send for Instance
impl Sync for Instance
impl Unpin for Instance
impl UnsafeUnpin for Instance
impl UnwindSafe for Instance
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more