mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 23:04:49 +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]]
|
||||
name = "codemp"
|
||||
version = "0.7.0-beta.1"
|
||||
version = "0.7.0-beta.2"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"codemp-proto",
|
||||
|
|
16
Cargo.toml
16
Cargo.toml
|
@ -11,7 +11,7 @@ authors = [
|
|||
]
|
||||
license = "GPL-3.0-only"
|
||||
edition = "2021"
|
||||
version = "0.7.0-beta.1"
|
||||
version = "0.7.0-beta.2"
|
||||
exclude = ["dist/*"]
|
||||
|
||||
[lib]
|
||||
|
@ -22,7 +22,6 @@ crate-type = ["cdylib"]
|
|||
# core
|
||||
tracing = "0.1"
|
||||
thiserror = "1.0"
|
||||
async-trait = "0.1"
|
||||
# crdt
|
||||
diamond-types = "1.0"
|
||||
# proto
|
||||
|
@ -53,6 +52,9 @@ napi-derive = { version="2.16", optional = true}
|
|||
# glue (python)
|
||||
pyo3 = { version = "0.22", features = ["extension-module", "experimental-async"], optional = true}
|
||||
|
||||
# extra
|
||||
async-trait = { version = "0.1", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
# glue (js)
|
||||
napi-build = { version = "2", optional = true }
|
||||
|
@ -60,13 +62,15 @@ napi-build = { version = "2", optional = true }
|
|||
pyo3-build-config = { version = "0.19", optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["async-trait"]
|
||||
# ffi
|
||||
rust = [] # used for ci matrix
|
||||
lua = ["mlua", "tracing-subscriber", "lazy_static"]
|
||||
java = ["lazy_static", "jni", "tracing-subscriber"]
|
||||
js = ["napi-build", "tracing-subscriber", "napi", "napi-derive"]
|
||||
python = ["pyo3", "tracing-subscriber", "pyo3-build-config"]
|
||||
# extra
|
||||
async-trait = ["dep:async-trait"]
|
||||
|
||||
# build with all features on docs.rs
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
[package.metadata.docs.rs] # enabled features when building on docs.rs
|
||||
features = ["lua", "java", "js", "python"]
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
use crate::errors::ControllerResult;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub(crate) trait ControllerWorker<T : Sized + Send + Sync> {
|
||||
type Controller : Controller<T>;
|
||||
type Tx;
|
||||
|
@ -29,7 +28,8 @@ pub(crate) trait ControllerWorker<T : Sized + Send + Sync> {
|
|||
/// [`Controller::poll`] combined with [`Controller::try_recv`].
|
||||
///
|
||||
/// [`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 {
|
||||
/// Enqueue a new value to be sent to all other users.
|
||||
async fn send(&self, x: T) -> ControllerResult<()>;
|
||||
|
|
|
@ -5,7 +5,6 @@ use std::sync::Arc;
|
|||
|
||||
use diamond_types::LocalVersion;
|
||||
use tokio::sync::{mpsc, oneshot, watch};
|
||||
use tonic::async_trait;
|
||||
|
||||
use crate::api::controller::{Controller, ControllerCallback};
|
||||
use crate::api::TextChange;
|
||||
|
@ -54,7 +53,7 @@ pub(crate) struct BufferControllerInner {
|
|||
pub(crate) callback: watch::Sender<Option<ControllerCallback<BufferController>>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||
impl Controller<TextChange> for BufferController {
|
||||
async fn poll(&self) -> ControllerResult<()> {
|
||||
if self.0.last_update.get() != *self.0.latest_version.borrow() {
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||
|
||||
use diamond_types::LocalVersion;
|
||||
use tokio::sync::{mpsc, oneshot, watch};
|
||||
use tonic::{async_trait, Streaming};
|
||||
use tonic::Streaming;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::api::controller::{ControllerCallback, ControllerWorker};
|
||||
|
@ -71,7 +71,6 @@ impl BufferWorker {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ControllerWorker<TextChange> for BufferWorker {
|
||||
type Controller = BufferController;
|
||||
type Tx = mpsc::Sender<Operation>;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use tokio::sync::{mpsc, oneshot, watch};
|
||||
use tonic::async_trait;
|
||||
|
||||
use crate::{api::{controller::ControllerCallback, Controller, Cursor}, errors::ControllerResult};
|
||||
use codemp_proto::cursor::CursorPosition;
|
||||
|
@ -26,7 +25,7 @@ pub(crate) struct CursorControllerInner {
|
|||
pub(crate) stop: mpsc::UnboundedSender<()>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||
impl Controller<Cursor> for CursorController {
|
||||
async fn send(&self, mut cursor: Cursor) -> ControllerResult<()> {
|
||||
if cursor.start > cursor.end {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use tokio::sync::{mpsc, oneshot, watch};
|
||||
use tonic::{Streaming, async_trait};
|
||||
use tonic::Streaming;
|
||||
|
||||
use crate::{api::{controller::{ControllerCallback, ControllerWorker}, Cursor}, ext::IgnorableError};
|
||||
use codemp_proto::cursor::{CursorPosition, CursorEvent};
|
||||
|
@ -52,7 +52,6 @@ impl CursorWorker {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ControllerWorker<Cursor> for CursorWorker {
|
||||
type Controller = CursorController;
|
||||
type Tx = mpsc::Sender<CursorPosition>;
|
||||
|
|
Loading…
Reference in a new issue