Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: config feature flag in lib-dispatch

appflowy9f60741de0f8
diff --git a/frontend/rust-lib/lib-dispatch/Cargo.toml b/frontend/rust-lib/lib-dispatch/Cargo.toml
index cc3615ab4b..d458c6c41b 100644
--- a/frontend/rust-lib/lib-dispatch/Cargo.toml
+++ b/frontend/rust-lib/lib-dispatch/Cargo.toml
@@ -22,8 +22,8 @@ thread-id = "3.3.0"
lazy_static = "1.4.0"
dyn-clone = "1.0"
derivative = "2.2.0"
-serde_json = {version = "1.0"}
-serde = { version = "1.0", features = ["derive"] }
+serde_json = {version = "1.0", optional = true }
+serde = { version = "1.0", features = ["derive"], optional = true }
dashmap = "5"
#optional crate
@@ -37,5 +37,5 @@ futures-util = "0.3.15"
[features]
default = ["use_protobuf"]
-use_serde = ["bincode"]
+use_serde = ["bincode", "serde_json", "serde"]
use_protobuf= ["protobuf"]
diff --git a/frontend/rust-lib/lib-dispatch/src/errors/errors.rs b/frontend/rust-lib/lib-dispatch/src/errors/errors.rs
index dbee088802..e469b186bf 100644
--- a/frontend/rust-lib/lib-dispatch/src/errors/errors.rs
+++ b/frontend/rust-lib/lib-dispatch/src/errors/errors.rs
@@ -6,7 +6,6 @@ use crate::{
use bytes::Bytes;
use dyn_clone::DynClone;
-use serde::{Serialize, Serializer};
use std::fmt;
use tokio::{sync::mpsc::error::SendError, task::JoinError};
@@ -86,11 +85,11 @@ impl From<DispatchError> for EventResponse {
err.inner_error().as_response()
}
}
-
-impl Serialize for DispatchError {
- fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
+#[cfg(feature = "use_serde")]
+impl serde::Serialize for DispatchError {
+ fn serialize<S>(&self, serializer: S) -> Result<<S as serde::Serializer>::Ok, <S as serde::Serializer>::Error>
where
- S: Serializer,
+ S: serde::Serializer,
{
serializer.serialize_str(&format!("{}", self))
}
diff --git a/frontend/rust-lib/lib-dispatch/src/request/payload.rs b/frontend/rust-lib/lib-dispatch/src/request/payload.rs
index a82e2c072a..c5d67e8413 100644
--- a/frontend/rust-lib/lib-dispatch/src/request/payload.rs
+++ b/frontend/rust-lib/lib-dispatch/src/request/payload.rs
@@ -4,7 +4,8 @@ use std::{fmt, fmt::Formatter};
pub enum PayloadError {}
// TODO: support stream data
-#[derive(Clone, serde::Serialize)]
+#[derive(Clone)]
+#[cfg_attr(feature = "user_serde", derive(serde::Serialize))]
pub enum Payload {
None,
Bytes(Bytes),
diff --git a/frontend/rust-lib/lib-dispatch/src/response/response.rs b/frontend/rust-lib/lib-dispatch/src/response/response.rs
index 812de68e84..cfad0e6f85 100644
--- a/frontend/rust-lib/lib-dispatch/src/response/response.rs
+++ b/frontend/rust-lib/lib-dispatch/src/response/response.rs
@@ -8,7 +8,8 @@ use crate::{
use derivative::*;
use std::{convert::TryFrom, fmt, fmt::Formatter};
-#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
+#[derive(Clone, Debug, Eq, PartialEq)]
+#[cfg_attr(feature = "user_serde", derive(serde::Serialize))]
pub enum StatusCode {
Ok = 0,
Err = 1,
@@ -16,7 +17,8 @@ pub enum StatusCode {
}
// serde user guide: https://serde.rs/field-attrs.html
-#[derive(Debug, Clone, serde::Serialize, Derivative)]
+#[derive(Debug, Clone, Derivative)]
+#[cfg_attr(feature = "user_serde", derive(serde::Serialize))]
pub struct EventResponse {
#[derivative(Debug = "ignore")]
pub payload: Payload,