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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
replace tryFrom &Bytes to Bytes
appflowy57b4a8e11473
diff --git a/rust-lib/dart-ffi/Cargo.toml b/rust-lib/dart-ffi/Cargo.tomlindex 3132ea54aa..b29f4558cf 100644--- a/rust-lib/dart-ffi/Cargo.toml+++ b/rust-lib/dart-ffi/Cargo.toml@@ -7,11 +7,11 @@ edition = "2018"[lib]name = "dart_ffi"# this value will change depending on the target os-# for iOS it would be `rlib`-# for Macos it would be `rlib`+# for iOS it would be `cdylib`+# for Macos it would be `cdylib`# for android it would be `c-dylib`-# default rlib-crate-type = ["rlib"]+# default cdylib+crate-type = ["cdylib"][dependencies]diff --git a/rust-lib/flowy-derive/src/proto_buf/deserialize.rs b/rust-lib/flowy-derive/src/proto_buf/deserialize.rsindex a490da261d..d84b90a2a5 100644--- a/rust-lib/flowy-derive/src/proto_buf/deserialize.rs+++ b/rust-lib/flowy-derive/src/proto_buf/deserialize.rs@@ -22,9 +22,9 @@ pub fn make_de_token_steam(ctxt: &Ctxt, ast: &ASTContainer) -> Option<TokenStrea});let de_token_stream: TokenStream = quote! {- impl std::convert::TryFrom<&bytes::Bytes> for #struct_ident {+ impl std::convert::TryFrom<bytes::Bytes> for #struct_ident {type Error = ::protobuf::ProtobufError;- fn try_from(bytes: &bytes::Bytes) -> Result<Self, Self::Error> {+ fn try_from(bytes: bytes::Bytes) -> Result<Self, Self::Error> {let mut pb: crate::protobuf::#pb_ty = ::protobuf::Message::parse_from_bytes(&bytes)?;#struct_ident::try_from(&mut pb)}diff --git a/rust-lib/flowy-dispatch/src/byte_trait.rs b/rust-lib/flowy-dispatch/src/byte_trait.rsindex 1c427f846e..531d4aab7a 100644--- a/rust-lib/flowy-dispatch/src/byte_trait.rs+++ b/rust-lib/flowy-dispatch/src/byte_trait.rs@@ -1,6 +1,7 @@use crate::errors::{DispatchError, InternalError};use bytes::Bytes;use protobuf::ProtobufError;+use std::convert::TryFrom;// To bytespub trait ToBytes {@@ -48,11 +49,13 @@ pub trait FromBytes: Sized {#[cfg(feature = "use_protobuf")]impl<T> FromBytes for Twhere- // https://stackoverflow.com/questions/62871045/tryfromu8-trait-bound-in-trait- T: for<'a> std::convert::TryFrom<&'a Bytes, Error = protobuf::ProtobufError>,+ // // https://stackoverflow.com/questions/62871045/tryfromu8-trait-bound-in-trait+ // T: for<'a> std::convert::TryFrom<&'a Bytes, Error =+ // protobuf::ProtobufError>,+ T: std::convert::TryFrom<Bytes, Error = protobuf::ProtobufError>,{fn parse_from_bytes(bytes: Bytes) -> Result<Self, DispatchError> {- let data = T::try_from(&bytes)?;+ let data = T::try_from(bytes.clone())?;Ok(data)}}diff --git a/rust-lib/flowy-net/src/request/request.rs b/rust-lib/flowy-net/src/request/request.rsindex e4959062c3..85ac9b65d2 100644--- a/rust-lib/flowy-net/src/request/request.rs+++ b/rust-lib/flowy-net/src/request/request.rs@@ -8,21 +8,22 @@ use std::{};use tokio::sync::{oneshot, oneshot::error::RecvError};-pub async fn http_post<T1, T2>(url: &str, data: T1) -> ResultFuture<T2, NetworkError>-where- T1: TryInto<Bytes, Error = ProtobufError> + Send + Sync + 'static,- T2: TryFrom<Bytes, Error = ProtobufError> + Send + Sync + 'static,-{- let url = url.to_owned();- ResultFuture::new(async move { post(url, data).await })-}+// pub async fn http_post<T1, T2>(url: &str, data: T1) -> ResultFuture<T2,+// NetworkError> where+// T1: TryInto<Bytes, Error = ProtobufError> + Send + Sync + 'static,+// T2: TryFrom<Bytes, Error = ProtobufError> + Send + Sync + 'static,+// {+// let url = url.to_owned();+// ResultFuture::new(async move { post(url, data).await })+// }-pub async fn post<T1, T2>(url: String, data: T1) -> Result<T2, NetworkError>+pub async fn http_post<T1, T2>(url: &str, data: T1) -> Result<T2, NetworkError>whereT1: TryInto<Bytes, Error = ProtobufError>,T2: TryFrom<Bytes, Error = ProtobufError>,{let request_bytes: Bytes = data.try_into()?;+ let url = url.to_owned();let (tx, rx) = oneshot::channel::<Result<Response, _>>();tokio::spawn(async move {diff --git a/rust-lib/flowy-user/src/services/user/user_server.rs b/rust-lib/flowy-user/src/services/user/user_server.rsindex 22eb701799..446b19ee73 100644--- a/rust-lib/flowy-user/src/services/user/user_server.rs+++ b/rust-lib/flowy-user/src/services/user/user_server.rs@@ -27,8 +27,10 @@ impl UserServerImpl {}impl UserServer for UserServerImpl {fn sign_up(&self, params: SignUpParams) -> ResultFuture<SignUpResponse, UserError> {- // http_post(SIGN_UP_URL.as_ref(), params)- unimplemented!()+ ResultFuture::new(async move {+ let a = http_post(SIGN_UP_URL.as_ref(), params).await?;+ Ok(a)+ })}fn sign_in(&self, _params: SignInParams) -> ResultFuture<SignInResponse, UserError> {