This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 295f891  Fix generated file duplication (#109)
295f891 is described below

commit 295f8911f2952a0c3dfab9aad9dc478737a63647
Author: Robert LU <[email protected]>
AuthorDate: Mon Feb 13 15:37:52 2023 +0800

    Fix generated file duplication (#109)
    
    * fix generated file duplication
    
    For dir `examples/echo`,
    * `src/echo/` is source dir.
    * `src/generated/` is generated source dir.
    * `proto/` is `*.proto` dir.
    
    * fix rustfmt error and license check
---
 examples/echo/build.rs                             |   2 +-
 examples/echo/src/echo/client.rs                   |   4 +-
 examples/echo/src/echo/server.rs                   |   2 +-
 .../src/{echo => generated}/grpc.examples.echo.rs  |   0
 examples/echo/src/{protos => generated}/mod.rs     |   3 +-
 examples/echo/src/lib.rs                           |   2 +-
 examples/echo/src/protos/hello_echo.rs             | 335 ---------------------
 7 files changed, 7 insertions(+), 341 deletions(-)

diff --git a/examples/echo/build.rs b/examples/echo/build.rs
index ecec1ab..8857af4 100644
--- a/examples/echo/build.rs
+++ b/examples/echo/build.rs
@@ -18,7 +18,7 @@
 use std::path::PathBuf;
 
 fn main() {
-    let path = PathBuf::from("./src/echo");
+    let path = PathBuf::from("./src/generated");
     println!("path: {:?}", path);
     dubbo_build::prost::configure()
         .output_dir(path)
diff --git a/examples/echo/src/echo/client.rs b/examples/echo/src/echo/client.rs
index 7312f72..f13d1e8 100644
--- a/examples/echo/src/echo/client.rs
+++ b/examples/echo/src/echo/client.rs
@@ -16,8 +16,8 @@
  */
 
 use dubbo::codegen::*;
-use example_echo::protos::hello_echo::echo_client::EchoClient;
-use example_echo::protos::hello_echo::EchoRequest;
+use example_echo::generated::generated::echo_client::EchoClient;
+use example_echo::generated::generated::EchoRequest;
 use futures_util::StreamExt;
 
 pub struct FakeFilter {}
diff --git a/examples/echo/src/echo/server.rs b/examples/echo/src/echo/server.rs
index d6c31b8..e09ba96 100644
--- a/examples/echo/src/echo/server.rs
+++ b/examples/echo/src/echo/server.rs
@@ -29,7 +29,7 @@ use tokio_stream::wrappers::ReceiverStream;
 use dubbo::codegen::*;
 // use dubbo::Dubbo;
 // use dubbo_config::RootConfig;
-use example_echo::protos::hello_echo::{
+use example_echo::generated::generated::{
     echo_server::{register_server, Echo, EchoServer},
     EchoRequest, EchoResponse,
 };
diff --git a/examples/echo/src/echo/grpc.examples.echo.rs 
b/examples/echo/src/generated/grpc.examples.echo.rs
similarity index 100%
rename from examples/echo/src/echo/grpc.examples.echo.rs
rename to examples/echo/src/generated/grpc.examples.echo.rs
diff --git a/examples/echo/src/protos/mod.rs 
b/examples/echo/src/generated/mod.rs
similarity index 93%
rename from examples/echo/src/protos/mod.rs
rename to examples/echo/src/generated/mod.rs
index d438812..7c1b089 100644
--- a/examples/echo/src/protos/mod.rs
+++ b/examples/echo/src/generated/mod.rs
@@ -15,4 +15,5 @@
  * limitations under the License.
  */
 
-pub mod hello_echo;
+#[path = "grpc.examples.echo.rs"]
+pub mod generated;
diff --git a/examples/echo/src/lib.rs b/examples/echo/src/lib.rs
index dc878ea..cfbbd56 100644
--- a/examples/echo/src/lib.rs
+++ b/examples/echo/src/lib.rs
@@ -15,4 +15,4 @@
  * limitations under the License.
  */
 
-pub mod protos;
+pub mod generated;
diff --git a/examples/echo/src/protos/hello_echo.rs 
b/examples/echo/src/protos/hello_echo.rs
deleted file mode 100644
index 9c487e6..0000000
--- a/examples/echo/src/protos/hello_echo.rs
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/// EchoRequest is the request for echo.
-#[derive(Clone, PartialEq, ::prost::Message)]
-pub struct EchoRequest {
-    #[prost(string, tag = "1")]
-    pub message: ::prost::alloc::string::String,
-}
-/// EchoResponse is the response for echo.
-#[derive(Clone, PartialEq, ::prost::Message)]
-pub struct EchoResponse {
-    #[prost(string, tag = "1")]
-    pub message: ::prost::alloc::string::String,
-}
-/// Generated client implementations.
-pub mod echo_client {
-    #![allow(unused_variables, dead_code, missing_docs, 
clippy::let_unit_value)]
-    use dubbo::codegen::*;
-    /// Echo is the echo service.
-    #[derive(Debug, Clone, Default)]
-    pub struct EchoClient {
-        inner: TripleClient,
-    }
-    impl EchoClient {
-        pub fn connect(host: String) -> Self {
-            let cli = TripleClient::connect(host);
-            EchoClient { inner: cli }
-        }
-        pub fn new(builder: ClientBuilder) -> Self {
-            Self {
-                inner: TripleClient::new(builder),
-            }
-        }
-        /// UnaryEcho is unary echo.
-        pub async fn unary_echo(
-            &mut self,
-            request: Request<super::EchoRequest>,
-        ) -> Result<Response<super::EchoResponse>, dubbo::status::Status> {
-            let codec =
-                dubbo::codegen::ProstCodec::<super::EchoRequest, 
super::EchoResponse>::default();
-            let invocation = RpcInvocation::default()
-                
.with_servie_unique_name(String::from("grpc.examples.echo.Echo"))
-                .with_method_name(String::from("UnaryEcho"));
-            let path = 
http::uri::PathAndQuery::from_static("/grpc.examples.echo.Echo/UnaryEcho");
-            self.inner.unary(request, codec, path, invocation).await
-        }
-        /// ServerStreamingEcho is server side streaming.
-        pub async fn server_streaming_echo(
-            &mut self,
-            request: Request<super::EchoRequest>,
-        ) -> Result<Response<Decoding<super::EchoResponse>>, 
dubbo::status::Status> {
-            let codec =
-                dubbo::codegen::ProstCodec::<super::EchoRequest, 
super::EchoResponse>::default();
-            let invocation = RpcInvocation::default()
-                
.with_servie_unique_name(String::from("grpc.examples.echo.Echo"))
-                .with_method_name(String::from("ServerStreamingEcho"));
-            let path = http::uri::PathAndQuery::from_static(
-                "/grpc.examples.echo.Echo/ServerStreamingEcho",
-            );
-            self.inner
-                .server_streaming(request, codec, path, invocation)
-                .await
-        }
-        /// ClientStreamingEcho is client side streaming.
-        pub async fn client_streaming_echo(
-            &mut self,
-            request: impl IntoStreamingRequest<Message = super::EchoRequest>,
-        ) -> Result<Response<super::EchoResponse>, dubbo::status::Status> {
-            let codec =
-                dubbo::codegen::ProstCodec::<super::EchoRequest, 
super::EchoResponse>::default();
-            let invocation = RpcInvocation::default()
-                
.with_servie_unique_name(String::from("grpc.examples.echo.Echo"))
-                .with_method_name(String::from("ClientStreamingEcho"));
-            let path = http::uri::PathAndQuery::from_static(
-                "/grpc.examples.echo.Echo/ClientStreamingEcho",
-            );
-            self.inner
-                .client_streaming(request, codec, path, invocation)
-                .await
-        }
-        /// BidirectionalStreamingEcho is bidi streaming.
-        pub async fn bidirectional_streaming_echo(
-            &mut self,
-            request: impl IntoStreamingRequest<Message = super::EchoRequest>,
-        ) -> Result<Response<Decoding<super::EchoResponse>>, 
dubbo::status::Status> {
-            let codec =
-                dubbo::codegen::ProstCodec::<super::EchoRequest, 
super::EchoResponse>::default();
-            let invocation = RpcInvocation::default()
-                
.with_servie_unique_name(String::from("grpc.examples.echo.Echo"))
-                .with_method_name(String::from("BidirectionalStreamingEcho"));
-            let path = http::uri::PathAndQuery::from_static(
-                "/grpc.examples.echo.Echo/BidirectionalStreamingEcho",
-            );
-            self.inner
-                .bidi_streaming(request, codec, path, invocation)
-                .await
-        }
-    }
-}
-/// Generated server implementations.
-pub mod echo_server {
-    #![allow(unused_variables, dead_code, missing_docs, 
clippy::let_unit_value)]
-    use dubbo::codegen::*;
-    ///Generated trait containing gRPC methods that should be implemented for 
use with EchoServer.
-    #[async_trait]
-    pub trait Echo: Send + Sync + 'static {
-        /// UnaryEcho is unary echo.
-        async fn unary_echo(
-            &self,
-            request: Request<super::EchoRequest>,
-        ) -> Result<Response<super::EchoResponse>, dubbo::status::Status>;
-        ///Server streaming response type for the ServerStreamingEcho method.
-        type ServerStreamingEchoStream: futures_util::Stream<Item = 
Result<super::EchoResponse, dubbo::status::Status>>
-            + Send
-            + 'static;
-        /// ServerStreamingEcho is server side streaming.
-        async fn server_streaming_echo(
-            &self,
-            request: Request<super::EchoRequest>,
-        ) -> Result<Response<Self::ServerStreamingEchoStream>, 
dubbo::status::Status>;
-        /// ClientStreamingEcho is client side streaming.
-        async fn client_streaming_echo(
-            &self,
-            request: Request<Decoding<super::EchoRequest>>,
-        ) -> Result<Response<super::EchoResponse>, dubbo::status::Status>;
-        ///Server streaming response type for the BidirectionalStreamingEcho 
method.
-        type BidirectionalStreamingEchoStream: futures_util::Stream<Item = 
Result<super::EchoResponse, dubbo::status::Status>>
-            + Send
-            + 'static;
-        /// BidirectionalStreamingEcho is bidi streaming.
-        async fn bidirectional_streaming_echo(
-            &self,
-            request: Request<Decoding<super::EchoRequest>>,
-        ) -> Result<Response<Self::BidirectionalStreamingEchoStream>, 
dubbo::status::Status>;
-    }
-    /// Echo is the echo service.
-    #[derive(Debug)]
-    pub struct EchoServer<T: Echo> {
-        inner: _Inner<T>,
-    }
-    struct _Inner<T>(Arc<T>);
-    impl<T: Echo> EchoServer<T> {
-        pub fn new(inner: T) -> Self {
-            Self {
-                inner: _Inner(Arc::new(inner)),
-            }
-        }
-        pub fn with_filter<F>(inner: T, filter: F) -> FilterService<Self, F>
-        where
-            F: Filter,
-        {
-            FilterService::new(Self::new(inner), filter)
-        }
-    }
-    impl<T, B> Service<http::Request<B>> for EchoServer<T>
-    where
-        T: Echo,
-        B: Body + Send + 'static,
-        B::Error: Into<StdError> + Send + 'static,
-    {
-        type Response = http::Response<BoxBody>;
-        type Error = std::convert::Infallible;
-        type Future = BoxFuture<Self::Response, Self::Error>;
-        fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), 
Self::Error>> {
-            Poll::Ready(Ok(()))
-        }
-        fn call(&mut self, req: http::Request<B>) -> Self::Future {
-            let inner = self.inner.clone();
-            match req.uri().path() {
-                "/grpc.examples.echo.Echo/UnaryEcho" => {
-                    #[allow(non_camel_case_types)]
-                    struct UnaryEchoServer<T: Echo> {
-                        inner: _Inner<T>,
-                    }
-                    impl<T: Echo> UnarySvc<super::EchoRequest> for 
UnaryEchoServer<T> {
-                        type Response = super::EchoResponse;
-                        type Future = BoxFuture<Response<Self::Response>, 
dubbo::status::Status>;
-                        fn call(&mut self, request: 
Request<super::EchoRequest>) -> Self::Future {
-                            let inner = self.inner.0.clone();
-                            let fut = async move { 
inner.unary_echo(request).await };
-                            Box::pin(fut)
-                        }
-                    }
-                    let fut = async move {
-                        let mut server = 
TripleServer::new(dubbo::codegen::ProstCodec::<
-                            super::EchoResponse,
-                            super::EchoRequest,
-                        >::default());
-                        let res = server.unary(UnaryEchoServer { inner }, 
req).await;
-                        Ok(res)
-                    };
-                    Box::pin(fut)
-                }
-                "/grpc.examples.echo.Echo/ServerStreamingEcho" => {
-                    #[allow(non_camel_case_types)]
-                    struct ServerStreamingEchoServer<T: Echo> {
-                        inner: _Inner<T>,
-                    }
-                    impl<T: Echo> ServerStreamingSvc<super::EchoRequest> for 
ServerStreamingEchoServer<T> {
-                        type Response = super::EchoResponse;
-                        type ResponseStream = T::ServerStreamingEchoStream;
-                        type Future =
-                            BoxFuture<Response<Self::ResponseStream>, 
dubbo::status::Status>;
-                        fn call(&mut self, request: 
Request<super::EchoRequest>) -> Self::Future {
-                            let inner = self.inner.0.clone();
-                            let fut = async move { 
inner.server_streaming_echo(request).await };
-                            Box::pin(fut)
-                        }
-                    }
-                    let fut = async move {
-                        let mut server = 
TripleServer::new(dubbo::codegen::ProstCodec::<
-                            super::EchoResponse,
-                            super::EchoRequest,
-                        >::default());
-                        let res = server
-                            .server_streaming(ServerStreamingEchoServer { 
inner }, req)
-                            .await;
-                        Ok(res)
-                    };
-                    Box::pin(fut)
-                }
-                "/grpc.examples.echo.Echo/ClientStreamingEcho" => {
-                    #[allow(non_camel_case_types)]
-                    struct ClientStreamingEchoServer<T: Echo> {
-                        inner: _Inner<T>,
-                    }
-                    impl<T: Echo> ClientStreamingSvc<super::EchoRequest> for 
ClientStreamingEchoServer<T> {
-                        type Response = super::EchoResponse;
-                        type Future = BoxFuture<Response<Self::Response>, 
dubbo::status::Status>;
-                        fn call(
-                            &mut self,
-                            request: Request<Decoding<super::EchoRequest>>,
-                        ) -> Self::Future {
-                            let inner = self.inner.0.clone();
-                            let fut = async move { 
inner.client_streaming_echo(request).await };
-                            Box::pin(fut)
-                        }
-                    }
-                    let fut = async move {
-                        let mut server = 
TripleServer::new(dubbo::codegen::ProstCodec::<
-                            super::EchoResponse,
-                            super::EchoRequest,
-                        >::default());
-                        let res = server
-                            .client_streaming(ClientStreamingEchoServer { 
inner }, req)
-                            .await;
-                        Ok(res)
-                    };
-                    Box::pin(fut)
-                }
-                "/grpc.examples.echo.Echo/BidirectionalStreamingEcho" => {
-                    #[allow(non_camel_case_types)]
-                    struct BidirectionalStreamingEchoServer<T: Echo> {
-                        inner: _Inner<T>,
-                    }
-                    impl<T: Echo> StreamingSvc<super::EchoRequest> for 
BidirectionalStreamingEchoServer<T> {
-                        type Response = super::EchoResponse;
-                        type ResponseStream = 
T::BidirectionalStreamingEchoStream;
-                        type Future =
-                            BoxFuture<Response<Self::ResponseStream>, 
dubbo::status::Status>;
-                        fn call(
-                            &mut self,
-                            request: Request<Decoding<super::EchoRequest>>,
-                        ) -> Self::Future {
-                            let inner = self.inner.0.clone();
-                            let fut =
-                                async move { 
inner.bidirectional_streaming_echo(request).await };
-                            Box::pin(fut)
-                        }
-                    }
-                    let fut = async move {
-                        let mut server = 
TripleServer::new(dubbo::codegen::ProstCodec::<
-                            super::EchoResponse,
-                            super::EchoRequest,
-                        >::default());
-                        let res = server
-                            .bidi_streaming(BidirectionalStreamingEchoServer { 
inner }, req)
-                            .await;
-                        Ok(res)
-                    };
-                    Box::pin(fut)
-                }
-                _ => Box::pin(async move {
-                    Ok(http::Response::builder()
-                        .status(200)
-                        .header("grpc-status", "12")
-                        .header("content-type", "application/grpc")
-                        .body(empty_body())
-                        .unwrap())
-                }),
-            }
-        }
-    }
-    impl<T: Echo> Clone for EchoServer<T> {
-        fn clone(&self) -> Self {
-            let inner = self.inner.clone();
-            Self { inner }
-        }
-    }
-    impl<T: Echo> Clone for _Inner<T> {
-        fn clone(&self) -> Self {
-            Self(self.0.clone())
-        }
-    }
-    impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
-        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-            write!(f, "{:?}", self.0)
-        }
-    }
-    pub fn register_server<T: Echo>(server: T) {
-        let s = EchoServer::new(server);
-        dubbo::protocol::triple::TRIPLE_SERVICES
-            .write()
-            .unwrap()
-            .insert(
-                "grpc.examples.echo.Echo".to_string(),
-                dubbo::utils::boxed_clone::BoxCloneService::new(s),
-            );
-    }
-}

Reply via email to