소스 검색

replace tryFrom &Bytes to Bytes

appflowy 3 년 전
부모
커밋
57b4a8e114

+ 4 - 4
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]

+ 2 - 2
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)
             }

+ 6 - 3
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 bytes
 pub trait ToBytes {
@@ -48,11 +49,13 @@ pub trait FromBytes: Sized {
 #[cfg(feature = "use_protobuf")]
 impl<T> FromBytes for T
 where
-    // 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)
     }
 }

+ 10 - 9
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>
 where
     T1: 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 {

+ 4 - 2
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> {