1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use quil_rs::{
    instruction::{Sharing, Vector},
    program::MemoryRegion,
};
use rigetti_pyo3::{
    impl_hash, impl_repr, py_wrap_data_struct,
    pyo3::{pymethods, PyResult, Python},
    PyTryFrom,
};

use crate::{
    impl_eq,
    instruction::{PySharing, PyVector},
};

py_wrap_data_struct! {
    #[derive(Debug, Eq, PartialEq, Hash)]
    #[pyo3(subclass)]
    PyMemoryRegion(MemoryRegion) as "MemoryRegion" {
        size: Vector => PyVector,
        sharing: Option<Sharing> => Option<PySharing>
    }
}
impl_repr!(PyMemoryRegion);
impl_hash!(PyMemoryRegion);
impl_eq!(PyMemoryRegion);

#[pymethods]
impl PyMemoryRegion {
    #[new]
    pub fn new(py: Python<'_>, size: PyVector, sharing: Option<PySharing>) -> PyResult<Self> {
        Ok(Self(MemoryRegion::new(
            Vector::py_try_from(py, &size)?,
            Option::<Sharing>::py_try_from(py, &sharing)?,
        )))
    }
}