mirror of
https://github.com/hexedtech/codemp-sublime.git
synced 2024-11-22 06:44:48 +01:00
Added errors wrappers and version bump
Former-commit-id: a9e1c1594f5d199499f7f08d273e2096f71f9bf1
This commit is contained in:
parent
c79529ce87
commit
31f296a55c
2 changed files with 31 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "CodempClient-Sublime"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -9,7 +9,7 @@ name = "codemp_client"
|
|||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.3" }
|
||||
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.4.4" }
|
||||
pyo3 = { version = "0.19", features = ["extension-module"] }
|
||||
pyo3-asyncio = { version = "0.19", features = ["tokio-runtime"] }
|
||||
tokio = "1.29.1"
|
||||
|
|
37
src/lib.rs
37
src/lib.rs
|
@ -1,18 +1,39 @@
|
|||
use std::{sync::Arc, error::Error};
|
||||
use std::{sync::Arc, error::Error, format};
|
||||
|
||||
use codemp::{
|
||||
client::CodempClient,
|
||||
controller::{cursor::{CursorSubscriber, CursorControllerHandle},
|
||||
buffer::{OperationControllerHandle, OperationControllerSubscriber}},
|
||||
proto::Position, factory::OperationFactory, tokio::sync::Mutex
|
||||
};
|
||||
use codemp::prelude::*;
|
||||
use codemp::errors::Error as CodempError;
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use pyo3::{
|
||||
prelude::*,
|
||||
exceptions::PyConnectionError,
|
||||
exceptions::{PyConnectionError, PyRuntimeError},
|
||||
types::{PyBool, PyString}
|
||||
};
|
||||
|
||||
struct PyCodempError(CodempError);
|
||||
impl From::<CodempError> for PyCodempError {
|
||||
fn from(err: CodempError) -> Self {
|
||||
PyCodempError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<PyCodempError> for PyErr {
|
||||
fn from(err: PyCodempError) -> PyErr {
|
||||
match err.0 {
|
||||
CodempError::Transport { status, message } => {
|
||||
PyConnectionError::new_err(format!("Transport error: ({}) {}", status, message))
|
||||
}
|
||||
CodempError::Channel { send } => {
|
||||
PyConnectionError::new_err(format!("Channel error (send:{})", send))
|
||||
},
|
||||
CodempError::InvalidState { msg } => {
|
||||
PyRuntimeError::new_err(format!("Invalid state: {}", msg))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn connect<'a>(py: Python<'a>, dest: String) -> PyResult<&'a PyAny> {
|
||||
// construct a python coroutine
|
||||
|
|
Loading…
Reference in a new issue