macro_rules! impl_exp_boilerplate {
    ($exp_type: ty) => { ... };
}
Expand description

A macro to generate boilerplate implementations for structs representing experiments.

This macro assists in the conversion between Rust’s trait system and Python’s class system. Given that PyO3 doesn’t support exposing trait methods directly to Python, this macro wraps each BaseExperiment trait method with a direct implementation, facilitating its export to Python.

The majority of methods are exported with their arguments and types preserved. Any deviations from this convention should be explicitly noted and elaborated upon.

Usage:

use nicompiler_backend::device::*;
use nicompiler_backend::channel::*;
use nicompiler_backend::*;
use pyo3::prelude::*;
use std::collections::HashMap;

#[pyclass]
struct CustomExperiment {
    devices: HashMap<String, Device>,
    some_property: f64,
}
impl_exp_boilerplate!(CustomExperiment);

// Implement additional methods which can be exposed to python
#[pymethods]
impl CustomExperiment {
    #[new]
    pub fn new(some_property: f64) -> Self {
        Self {
            devices: HashMap::new(),
            some_property
        }
    }
}

This will generate the required implementations and additional Python bindings for CustomExperiment.