Skip to main content

type_interface

Attribute Macro type_interface 

Source
#[type_interface]
Expand description

Declare a Type interface, which can be implemented by any Type.

If the interface requires any other interface to be already implemented, they can be specified super-traits.

When an Attribute is verified, its interfaces are also automatically verified, with guarantee that a super-interface is verified before an interface itself is.

Example: Here Super1 and Super2 are super interfaces for the interface MyTypeIntr.

use pliron::derive::type_interface;
#[type_interface]
trait Super1 {
    fn verify(_type: &dyn Type, _ctx: &Context) -> Result<()>
    where
        Self: Sized,
    {
        Ok(())
    }
}

#[type_interface]
trait Super2 {
    fn verify(_type: &dyn Type, _ctx: &Context) -> Result<()>
    where
        Self: Sized,
    {
        Ok(())
    }
}

#[type_interface]
// MyTypeIntr is my best type interface.
trait MyTypeIntr: Super1 + Super2 {
    fn verify(_type: &dyn Type, _ctx: &Context) -> Result<()>
    where
        Self: Sized,
    {
        Ok(())
    }
}