mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
feat(python): finish wrapping the new glue in the new pyo3 stuff
This commit is contained in:
parent
3fe6d224e3
commit
07f656cbe5
1 changed files with 6 additions and 14 deletions
|
@ -10,18 +10,13 @@ use pyo3::prelude::*;
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
impl Client {
|
impl Client {
|
||||||
#[new]
|
#[new]
|
||||||
async fn pyconnect(host: String, username: String, password: String) -> PyResult<Self> {
|
fn pyconnect(host: String, username: String, password: String) -> crate::Result<Self> {
|
||||||
Ok(Client::new(host, username, password));
|
super::tokio().block_on(async move { Client::new(host, username, password).await })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "join_workspace")]
|
#[pyo3(name = "join_workspace")]
|
||||||
fn pyjoin_workspace<'a>(&'a self, py: Python<'a>, workspace: String) -> PyResult<&PyAny> {
|
async fn pyjoin_workspace(&self, workspace: String) -> crate::Result<Workspace> {
|
||||||
let rc = self.clone();
|
self.join_workspace(workspace).await
|
||||||
|
|
||||||
pyo3_asyncio::tokio::future_into_py(py, async move {
|
|
||||||
let workspace: Workspace = rc.join_workspace(workspace.as_str()).await?;
|
|
||||||
Python::with_gil(|py| Py::new(py, workspace))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "leave_workspace")]
|
#[pyo3(name = "leave_workspace")]
|
||||||
|
@ -31,11 +26,8 @@ impl Client {
|
||||||
|
|
||||||
// join a workspace
|
// join a workspace
|
||||||
#[pyo3(name = "get_workspace")]
|
#[pyo3(name = "get_workspace")]
|
||||||
fn pyget_workspace(&self, py: Python<'_>, id: String) -> PyResult<Option<Py<Workspace>>> {
|
fn pyget_workspace(&self, id: String) -> Option<Workspace> {
|
||||||
match self.get_workspace(id.as_str()) {
|
self.get_workspace(id.as_str())
|
||||||
Some(ws) => Ok(Some(Py::new(py, ws)?)),
|
|
||||||
None => Ok(None),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "active_workspaces")]
|
#[pyo3(name = "active_workspaces")]
|
||||||
|
|
Loading…
Reference in a new issue