diff --git a/Cargo.lock b/Cargo.lock index 06d797d..34a4128 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 700a936..4c6ea0c 100644 --- a/Cargo.toml +++ b/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"] diff --git a/src/api/controller.rs b/src/api/controller.rs index cea8ee3..f56933c 100644 --- a/src/api/controller.rs +++ b/src/api/controller.rs @@ -5,7 +5,6 @@ use crate::errors::ControllerResult; -#[async_trait::async_trait] pub(crate) trait ControllerWorker { type Controller : Controller; type Tx; @@ -29,7 +28,8 @@ pub(crate) trait ControllerWorker { /// [`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 : Sized + Send + Sync { /// Enqueue a new value to be sent to all other users. async fn send(&self, x: T) -> ControllerResult<()>; diff --git a/src/buffer/controller.rs b/src/buffer/controller.rs index b2a020b..b91016b 100644 --- a/src/buffer/controller.rs +++ b/src/buffer/controller.rs @@ -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>>, } -#[async_trait] +#[cfg_attr(feature = "async-trait", async_trait::async_trait)] impl Controller for BufferController { async fn poll(&self) -> ControllerResult<()> { if self.0.last_update.get() != *self.0.latest_version.borrow() { diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index 1743c20..a9353ba 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -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 for BufferWorker { type Controller = BufferController; type Tx = mpsc::Sender; diff --git a/src/cursor/controller.rs b/src/cursor/controller.rs index e8dd208..b4bf6a2 100644 --- a/src/cursor/controller.rs +++ b/src/cursor/controller.rs @@ -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 for CursorController { async fn send(&self, mut cursor: Cursor) -> ControllerResult<()> { if cursor.start > cursor.end { diff --git a/src/cursor/worker.rs b/src/cursor/worker.rs index e2eff7f..bbe2a13 100644 --- a/src/cursor/worker.rs +++ b/src/cursor/worker.rs @@ -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 for CursorWorker { type Controller = CursorController; type Tx = mpsc::Sender;