#[derive_type_get]Expand description
Derive get methods for types that retrieve interned types.
Note: It is suggested to use the pliron_type macro instead of using this macro directly.
The documention here is useful though, because pliron_type’s generate_get field
expands to this macro.
This macro generates appropriate get methods based on the struct’s fields:
- For unit structs: generates a singleton
get(ctx: &Context)method - For structs with fields (named or tuple): generates a
get(ctx: &mut Context, ...)method
§Examples
§Named fields struct:
use pliron::derive::{def_type, derive_type_get, format_type, verify_succ};
use pliron::context::Context;
#[verify_succ]
#[def_type("my_dialect.vector_type")]
#[format_type]
#[derive_type_get] // Auto-generates get method
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct VectorType {
elem_ty: u32,
num_elems: u32,
}
// Usage of the auto-generated get method:
let vector_type = VectorType::get(ctx, 42, 8); // get(ctx, elem_ty, num_elems)§Tuple struct:
use pliron::derive::{def_type, derive_type_get, format_type, verify_succ};
use pliron::context::Context;
#[verify_succ]
#[def_type("my_dialect.tuple_type")]
#[format_type]
#[derive_type_get] // Auto-generates get method
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TupleType(u32, String, bool);
// Usage of the auto-generated get method:
let tuple_type = TupleType::get(ctx, 42, "hello".to_string(), true); // get(ctx, field_0, field_1, field_2)§Unit struct:
use pliron::derive::{def_type, derive_type_get, format_type, verify_succ};
use pliron::context::Context;
#[verify_succ]
#[def_type("my_dialect.unit_type")]
#[format_type]
#[derive_type_get] // Auto-generates singleton get method
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UnitType;
// Usage of the auto-generated singleton get method:
let unit_type = UnitType::get(ctx); // get(ctx) - no additional parameters