mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
feat: don't use async-trait for api::Controller
make it still available via feature `async-trait` if it is necessary to use auto traits downstream, however documentation should now be more readable
This commit is contained in:
parent
bebcf5d3e1
commit
04e021f964
7 changed files with 17 additions and 17 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -231,7 +231,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "codemp"
|
name = "codemp"
|
||||||
version = "0.7.0-beta.1"
|
version = "0.7.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"codemp-proto",
|
"codemp-proto",
|
||||||
|
|
16
Cargo.toml
16
Cargo.toml
|
@ -11,7 +11,7 @@ authors = [
|
||||||
]
|
]
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
version = "0.7.0-beta.1"
|
version = "0.7.0-beta.2"
|
||||||
exclude = ["dist/*"]
|
exclude = ["dist/*"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -22,7 +22,6 @@ crate-type = ["cdylib"]
|
||||||
# core
|
# core
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
async-trait = "0.1"
|
|
||||||
# crdt
|
# crdt
|
||||||
diamond-types = "1.0"
|
diamond-types = "1.0"
|
||||||
# proto
|
# proto
|
||||||
|
@ -53,6 +52,9 @@ napi-derive = { version="2.16", optional = true}
|
||||||
# glue (python)
|
# glue (python)
|
||||||
pyo3 = { version = "0.22", features = ["extension-module", "experimental-async"], optional = true}
|
pyo3 = { version = "0.22", features = ["extension-module", "experimental-async"], optional = true}
|
||||||
|
|
||||||
|
# extra
|
||||||
|
async-trait = { version = "0.1", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
# glue (js)
|
# glue (js)
|
||||||
napi-build = { version = "2", optional = true }
|
napi-build = { version = "2", optional = true }
|
||||||
|
@ -60,13 +62,15 @@ napi-build = { version = "2", optional = true }
|
||||||
pyo3-build-config = { version = "0.19", optional = true }
|
pyo3-build-config = { version = "0.19", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["async-trait"]
|
||||||
|
# ffi
|
||||||
rust = [] # used for ci matrix
|
rust = [] # used for ci matrix
|
||||||
lua = ["mlua", "tracing-subscriber", "lazy_static"]
|
lua = ["mlua", "tracing-subscriber", "lazy_static"]
|
||||||
java = ["lazy_static", "jni", "tracing-subscriber"]
|
java = ["lazy_static", "jni", "tracing-subscriber"]
|
||||||
js = ["napi-build", "tracing-subscriber", "napi", "napi-derive"]
|
js = ["napi-build", "tracing-subscriber", "napi", "napi-derive"]
|
||||||
python = ["pyo3", "tracing-subscriber", "pyo3-build-config"]
|
python = ["pyo3", "tracing-subscriber", "pyo3-build-config"]
|
||||||
|
# extra
|
||||||
|
async-trait = ["dep:async-trait"]
|
||||||
|
|
||||||
# build with all features on docs.rs
|
[package.metadata.docs.rs] # enabled features when building on docs.rs
|
||||||
[package.metadata.docs.rs]
|
features = ["lua", "java", "js", "python"]
|
||||||
all-features = true
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
use crate::errors::ControllerResult;
|
use crate::errors::ControllerResult;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub(crate) trait ControllerWorker<T : Sized + Send + Sync> {
|
pub(crate) trait ControllerWorker<T : Sized + Send + Sync> {
|
||||||
type Controller : Controller<T>;
|
type Controller : Controller<T>;
|
||||||
type Tx;
|
type Tx;
|
||||||
|
@ -29,7 +28,8 @@ pub(crate) trait ControllerWorker<T : Sized + Send + Sync> {
|
||||||
/// [`Controller::poll`] combined with [`Controller::try_recv`].
|
/// [`Controller::poll`] combined with [`Controller::try_recv`].
|
||||||
///
|
///
|
||||||
/// [`crate::ext::select_buffer`] may provide a useful helper for managing multiple controllers.
|
/// [`crate::ext::select_buffer`] may provide a useful helper for managing multiple controllers.
|
||||||
#[async_trait::async_trait]
|
#[allow(async_fn_in_trait)]
|
||||||
|
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||||
pub trait Controller<T : Sized + Send + Sync> : Sized + Send + Sync {
|
pub trait Controller<T : Sized + Send + Sync> : Sized + Send + Sync {
|
||||||
/// Enqueue a new value to be sent to all other users.
|
/// Enqueue a new value to be sent to all other users.
|
||||||
async fn send(&self, x: T) -> ControllerResult<()>;
|
async fn send(&self, x: T) -> ControllerResult<()>;
|
||||||
|
|
|
@ -5,7 +5,6 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use diamond_types::LocalVersion;
|
use diamond_types::LocalVersion;
|
||||||
use tokio::sync::{mpsc, oneshot, watch};
|
use tokio::sync::{mpsc, oneshot, watch};
|
||||||
use tonic::async_trait;
|
|
||||||
|
|
||||||
use crate::api::controller::{Controller, ControllerCallback};
|
use crate::api::controller::{Controller, ControllerCallback};
|
||||||
use crate::api::TextChange;
|
use crate::api::TextChange;
|
||||||
|
@ -54,7 +53,7 @@ pub(crate) struct BufferControllerInner {
|
||||||
pub(crate) callback: watch::Sender<Option<ControllerCallback<BufferController>>>,
|
pub(crate) callback: watch::Sender<Option<ControllerCallback<BufferController>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||||
impl Controller<TextChange> for BufferController {
|
impl Controller<TextChange> for BufferController {
|
||||||
async fn poll(&self) -> ControllerResult<()> {
|
async fn poll(&self) -> ControllerResult<()> {
|
||||||
if self.0.last_update.get() != *self.0.latest_version.borrow() {
|
if self.0.last_update.get() != *self.0.latest_version.borrow() {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use diamond_types::LocalVersion;
|
use diamond_types::LocalVersion;
|
||||||
use tokio::sync::{mpsc, oneshot, watch};
|
use tokio::sync::{mpsc, oneshot, watch};
|
||||||
use tonic::{async_trait, Streaming};
|
use tonic::Streaming;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::api::controller::{ControllerCallback, ControllerWorker};
|
use crate::api::controller::{ControllerCallback, ControllerWorker};
|
||||||
|
@ -71,7 +71,6 @@ impl BufferWorker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ControllerWorker<TextChange> for BufferWorker {
|
impl ControllerWorker<TextChange> for BufferWorker {
|
||||||
type Controller = BufferController;
|
type Controller = BufferController;
|
||||||
type Tx = mpsc::Sender<Operation>;
|
type Tx = mpsc::Sender<Operation>;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use tokio::sync::{mpsc, oneshot, watch};
|
use tokio::sync::{mpsc, oneshot, watch};
|
||||||
use tonic::async_trait;
|
|
||||||
|
|
||||||
use crate::{api::{controller::ControllerCallback, Controller, Cursor}, errors::ControllerResult};
|
use crate::{api::{controller::ControllerCallback, Controller, Cursor}, errors::ControllerResult};
|
||||||
use codemp_proto::cursor::CursorPosition;
|
use codemp_proto::cursor::CursorPosition;
|
||||||
|
@ -26,7 +25,7 @@ pub(crate) struct CursorControllerInner {
|
||||||
pub(crate) stop: mpsc::UnboundedSender<()>,
|
pub(crate) stop: mpsc::UnboundedSender<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||||
impl Controller<Cursor> for CursorController {
|
impl Controller<Cursor> for CursorController {
|
||||||
async fn send(&self, mut cursor: Cursor) -> ControllerResult<()> {
|
async fn send(&self, mut cursor: Cursor) -> ControllerResult<()> {
|
||||||
if cursor.start > cursor.end {
|
if cursor.start > cursor.end {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use tokio::sync::{mpsc, oneshot, watch};
|
use tokio::sync::{mpsc, oneshot, watch};
|
||||||
use tonic::{Streaming, async_trait};
|
use tonic::Streaming;
|
||||||
|
|
||||||
use crate::{api::{controller::{ControllerCallback, ControllerWorker}, Cursor}, ext::IgnorableError};
|
use crate::{api::{controller::{ControllerCallback, ControllerWorker}, Cursor}, ext::IgnorableError};
|
||||||
use codemp_proto::cursor::{CursorPosition, CursorEvent};
|
use codemp_proto::cursor::{CursorPosition, CursorEvent};
|
||||||
|
@ -52,7 +52,6 @@ impl CursorWorker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ControllerWorker<Cursor> for CursorWorker {
|
impl ControllerWorker<Cursor> for CursorWorker {
|
||||||
type Controller = CursorController;
|
type Controller = CursorController;
|
||||||
type Tx = mpsc::Sender<CursorPosition>;
|
type Tx = mpsc::Sender<CursorPosition>;
|
||||||
|
|
Loading…
Reference in a new issue