diff --git a/.idea/appflowy_client.iml b/.idea/appflowy_client.iml
index 42434a43ef..ab4b547fce 100644
--- a/.idea/appflowy_client.iml
+++ b/.idea/appflowy_client.iml
@@ -36,6 +36,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/rust-lib/flowy-sys/Cargo.toml b/rust-lib/flowy-sys/Cargo.toml
index b8dc7ca2bc..f6c7d7c5e1 100644
--- a/rust-lib/flowy-sys/Cargo.toml
+++ b/rust-lib/flowy-sys/Cargo.toml
@@ -17,13 +17,19 @@ tokio = { version = "1", features = ["full"] }
uuid = { version = "0.8", features = ["serde", "v4"] }
log = "0.4.14"
env_logger = "0.8"
-serde = { version = "1.0", features = ["derive"] }
-serde_json = "1.0"
serde_with = "1.9.4"
thread-id = "3.3.0"
lazy_static = "1.4.0"
dyn-clone = "1.0"
+#optional crate
+bincode = { version = "1.3", optional = true}
+serde = { version = "1.0", features = ["derive"], optional = true }
+serde_json = {version = "1.0", optional = true}
+
[dev-dependencies]
tokio = { version = "1", features = ["full"] }
futures-util = "0.3.15"
+
+[features]
+use_serde = ["bincode", "serde", "serde_json"]
diff --git a/rust-lib/flowy-sys/src/error/error.rs b/rust-lib/flowy-sys/src/error/error.rs
index 52243567b2..fccb16f53e 100644
--- a/rust-lib/flowy-sys/src/error/error.rs
+++ b/rust-lib/flowy-sys/src/error/error.rs
@@ -6,6 +6,9 @@ use dyn_clone::DynClone;
use std::{fmt, option::NoneError};
use tokio::sync::mpsc::error::SendError;
+#[cfg(feature = "use_serde")]
+use serde::{Deserialize, Serialize, Serializer};
+
pub trait Error: fmt::Debug + fmt::Display + DynClone {
fn status_code(&self) -> StatusCode;
@@ -94,3 +97,13 @@ where
fn as_response(&self) -> EventResponse { EventResponseBuilder::Err().data(format!("{}", self.inner)).build() }
}
+
+#[cfg(feature = "use_serde")]
+impl Serialize for SystemError {
+ fn serialize(&self, serializer: S) -> Result<::Ok, ::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_str(&format!("{}", self))
+ }
+}
diff --git a/rust-lib/flowy-sys/src/request/request.rs b/rust-lib/flowy-sys/src/request/request.rs
index 68b7800c02..7776a3f65e 100644
--- a/rust-lib/flowy-sys/src/request/request.rs
+++ b/rust-lib/flowy-sys/src/request/request.rs
@@ -1,16 +1,18 @@
use std::future::Future;
use crate::{
- error::SystemError,
+ error::{InternalError, SystemError},
module::Event,
request::payload::Payload,
util::ready::{ready, Ready},
};
+use futures_core::ready;
use std::{
fmt::{Debug, Display},
hash::Hash,
+ pin::Pin,
+ task::{Context, Poll},
};
-
#[derive(Clone, Debug)]
pub struct EventRequest {
id: String,
@@ -60,7 +62,46 @@ impl FromRequest for () {
#[doc(hidden)]
impl FromRequest for String {
type Error = SystemError;
- type Future = Ready>;
+ type Future = Ready>;
- fn from_request(_req: &EventRequest, _payload: &mut Payload) -> Self::Future { ready(Ok("".to_string())) }
+ fn from_request(req: &EventRequest, _payload: &mut Payload) -> Self::Future {
+ match &req.data {
+ None => ready(Err(InternalError::new("Expected string but request had data").into())),
+ Some(buf) => ready(Ok(String::from_utf8_lossy(buf).into_owned())),
+ }
+ }
+}
+
+#[doc(hidden)]
+impl FromRequest for Result
+where
+ T: FromRequest,
+{
+ type Error = SystemError;
+ type Future = FromRequestFuture;
+
+ fn from_request(req: &EventRequest, payload: &mut Payload) -> Self::Future {
+ FromRequestFuture {
+ fut: T::from_request(req, payload),
+ }
+ }
+}
+
+#[pin_project::pin_project]
+pub struct FromRequestFuture {
+ #[pin]
+ fut: Fut,
+}
+
+impl Future for FromRequestFuture
+where
+ Fut: Future