mirror of
https://github.com/ankitects/anki.git
synced 2025-11-10 06:37:12 -05:00
If we go ahead with betterproto on the Python side, it will mean bumping the minimum Python dependency to 3.7.
33 lines
685 B
Rust
33 lines
685 B
Rust
use ankirs::bridge::Bridge as RustBridge;
|
|
use pyo3::prelude::*;
|
|
use pyo3::types::PyBytes;
|
|
|
|
#[pyclass]
|
|
struct Bridge {
|
|
bridge: RustBridge,
|
|
}
|
|
|
|
#[pymethods]
|
|
impl Bridge {
|
|
#[new]
|
|
fn init(obj: &PyRawObject) {
|
|
obj.init({
|
|
Bridge {
|
|
bridge: Default::default(),
|
|
}
|
|
});
|
|
}
|
|
|
|
fn command(&mut self, py: Python, input: &PyBytes) -> PyResult<PyObject> {
|
|
let out_bytes = self.bridge.run_command_bytes(input.as_bytes());
|
|
let out_obj = PyBytes::new(py, &out_bytes);
|
|
Ok(out_obj.into())
|
|
}
|
|
}
|
|
|
|
#[pymodule]
|
|
fn _ankirs(_py: Python, m: &PyModule) -> PyResult<()> {
|
|
m.add_class::<Bridge>()?;
|
|
|
|
Ok(())
|
|
}
|