Skip to content

Commit

Permalink
chore: add constructors for grpc types
Browse files Browse the repository at this point in the history
  • Loading branch information
jselig-rigetti committed Jun 6, 2023
1 parent 327f984 commit 6ce0078
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions crates/python/src/grpc/models/translation.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
use qcs_api_client_grpc::services::translation::{
translation_options::TranslationBackend, BackendV1Options, BackendV2Options, TranslationOptions,
};
use rigetti_pyo3::{py_wrap_data_struct, py_wrap_type, py_wrap_union_enum, create_init_submodule};
use rigetti_pyo3::{
create_init_submodule, py_wrap_data_struct, py_wrap_type, py_wrap_union_enum,
pyo3::{pymethods, PyResult},
};

py_wrap_type! {
#[derive(Default)]
PyBackendV1Options(BackendV1Options) as "BackendV1Options";
}

#[pymethods]
impl PyBackendV1Options {
#[new]
fn __new__() -> PyResult<Self> {
Ok(Self::default())
}
}

py_wrap_type! {
#[derive(Default)]
PyBackendV2Options(BackendV2Options) as "BackendV2Options";
}

#[pymethods]
impl PyBackendV2Options {
#[new]
fn __new__() -> PyResult<Self> {
Ok(Self::default())
}
}

py_wrap_union_enum! {
PyTranslationBackend(TranslationBackend) as "TranslationBackend" {
v1: V1 => PyBackendV1Options,
Expand All @@ -27,11 +46,21 @@ py_wrap_data_struct! {
}
}

#[pymethods]
impl PyTranslationOptions {
#[new]
fn __new__(translation_backend: Option<PyTranslationBackend>) -> PyResult<Self> {
Ok(Self(TranslationOptions {
translation_backend: translation_backend.map(|b| b.0),
}))
}
}

create_init_submodule! {
classes: [
PyTranslationBackend,
PyTranslationOptions,
PyBackendV1Options,
PyBackendV2Options
],
}
}

0 comments on commit 6ce0078

Please sign in to comment.