mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
use separate fn to init backend, for future pyo3 0.9 release compat
This commit is contained in:
parent
d0ee95c4cd
commit
00f431d94e
2 changed files with 10 additions and 12 deletions
|
@ -96,7 +96,7 @@ class RustBackend:
|
|||
media_folder_path=media_folder_path,
|
||||
media_db_path=media_db_path,
|
||||
)
|
||||
self._backend = ankirspy.Backend(init_msg.SerializeToString())
|
||||
self._backend = ankirspy.open_backend(init_msg.SerializeToString())
|
||||
|
||||
def _run_command(self, input: pb.BackendInput) -> pb.BackendOutput:
|
||||
input_bytes = input.SerializeToString()
|
||||
|
|
|
@ -13,19 +13,16 @@ fn buildhash() -> &'static str {
|
|||
include_str!("../../meta/buildhash").trim()
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn open_backend(init_msg: &PyBytes) -> PyResult<Backend> {
|
||||
match init_backend(init_msg.as_bytes()) {
|
||||
Ok(backend) => Ok(Backend { backend }),
|
||||
Err(e) => Err(exceptions::Exception::py_err(e)),
|
||||
}
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl Backend {
|
||||
#[new]
|
||||
fn init(obj: &PyRawObject, init_msg: &PyBytes) -> PyResult<()> {
|
||||
match init_backend(init_msg.as_bytes()) {
|
||||
Ok(backend) => {
|
||||
obj.init({ Backend { backend } });
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(exceptions::Exception::py_err(e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn command(&mut self, py: Python, input: &PyBytes) -> PyObject {
|
||||
let out_bytes = self.backend.run_command_bytes(input.as_bytes());
|
||||
let out_obj = PyBytes::new(py, &out_bytes);
|
||||
|
@ -37,6 +34,7 @@ impl Backend {
|
|||
fn ankirspy(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_class::<Backend>()?;
|
||||
m.add_wrapped(wrap_pyfunction!(buildhash)).unwrap();
|
||||
m.add_wrapped(wrap_pyfunction!(open_backend)).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue