2023-04-17 14:56:00 +02:00
|
|
|
pub mod cursor;
|
2023-07-01 13:54:34 +02:00
|
|
|
pub mod errors;
|
2023-07-30 17:48:55 +02:00
|
|
|
pub mod buffer;
|
2023-04-07 03:05:21 +02:00
|
|
|
|
2023-08-16 18:58:42 +02:00
|
|
|
pub mod client;
|
2023-07-30 22:58:24 +02:00
|
|
|
|
2023-08-16 23:09:47 +02:00
|
|
|
#[cfg(feature = "static")]
|
|
|
|
pub mod instance;
|
|
|
|
|
2023-08-17 02:58:55 +02:00
|
|
|
pub mod prelude;
|
|
|
|
|
2023-04-07 03:05:21 +02:00
|
|
|
pub use tonic;
|
|
|
|
pub use tokio;
|
2023-07-02 23:59:04 +02:00
|
|
|
pub use operational_transform as ot;
|
2023-07-01 13:54:34 +02:00
|
|
|
|
2023-07-30 22:58:24 +02:00
|
|
|
#[cfg(feature = "proto")]
|
2023-08-16 17:08:31 +02:00
|
|
|
#[allow(non_snake_case)]
|
2023-07-30 22:58:24 +02:00
|
|
|
pub mod proto {
|
2023-08-16 17:08:31 +02:00
|
|
|
tonic::include_proto!("codemp.buffer");
|
|
|
|
tonic::include_proto!("codemp.cursor");
|
2023-07-30 22:58:24 +02:00
|
|
|
}
|
2023-07-30 17:48:55 +02:00
|
|
|
|
2023-08-17 02:58:55 +02:00
|
|
|
pub use errors::Error;
|
2023-07-30 22:58:24 +02:00
|
|
|
|
2023-08-17 04:36:59 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-07-30 22:58:24 +02:00
|
|
|
#[tonic::async_trait] // TODO move this somewhere?
|
|
|
|
pub(crate) trait ControllerWorker<T> {
|
2023-08-16 18:58:42 +02:00
|
|
|
type Controller : Controller<T>;
|
|
|
|
type Tx;
|
|
|
|
type Rx;
|
|
|
|
|
|
|
|
fn subscribe(&self) -> Self::Controller;
|
|
|
|
async fn work(self, tx: Self::Tx, rx: Self::Rx);
|
2023-07-30 17:48:55 +02:00
|
|
|
}
|
|
|
|
|
2023-07-30 22:58:24 +02:00
|
|
|
#[tonic::async_trait]
|
2023-08-17 04:36:59 +02:00
|
|
|
pub trait Controller<T> : Sized + Send + Sync {
|
2023-08-16 18:58:42 +02:00
|
|
|
type Input;
|
|
|
|
|
2023-08-17 02:58:55 +02:00
|
|
|
async fn send(&self, x: Self::Input) -> Result<(), Error>;
|
|
|
|
async fn recv(&self) -> Result<T, Error>;
|
2023-08-17 04:36:59 +02:00
|
|
|
|
2023-08-18 03:58:42 +02:00
|
|
|
fn callback<F>(self: Arc<Self>, rt: &tokio::runtime::Runtime, mut cb: F)
|
2023-08-17 04:36:59 +02:00
|
|
|
where Self : 'static, F : FnMut(T) + Sync + Send + 'static
|
|
|
|
{
|
|
|
|
let x = Arc::new(self);
|
2023-08-18 03:58:42 +02:00
|
|
|
rt.spawn(async move {
|
2023-08-17 04:36:59 +02:00
|
|
|
while let Ok(data) = x.recv().await {
|
|
|
|
cb(data)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-07-30 17:48:55 +02:00
|
|
|
}
|