1use quil_rs::{
2 instruction::{Sharing, Vector},
3 program::MemoryRegion,
4};
5use rigetti_pyo3::{
6 impl_hash, impl_repr, py_wrap_data_struct,
7 pyo3::{pymethods, PyResult, Python},
8 PyTryFrom,
9};
10
11use crate::{
12 impl_eq,
13 instruction::{PySharing, PyVector},
14};
15
16py_wrap_data_struct! {
17 #[derive(Debug, Eq, PartialEq, Hash)]
18 #[pyo3(subclass)]
19 PyMemoryRegion(MemoryRegion) as "MemoryRegion" {
20 size: Vector => PyVector,
21 sharing: Option<Sharing> => Option<PySharing>
22 }
23}
24impl_repr!(PyMemoryRegion);
25impl_hash!(PyMemoryRegion);
26impl_eq!(PyMemoryRegion);
27
28#[pymethods]
29impl PyMemoryRegion {
30 #[new]
31 pub fn new(py: Python<'_>, size: PyVector, sharing: Option<PySharing>) -> PyResult<Self> {
32 Ok(Self(MemoryRegion::new(
33 Vector::py_try_from(py, &size)?,
34 Option::<Sharing>::py_try_from(py, &sharing)?,
35 )))
36 }
37}