You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2022/07/23 14:44:35 UTC
[dubbo-rust] 33/38: style: cargo check
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-rust.git
commit 6337143b5f053ee70ce15a389533f5c061d201ee
Author: yangyang <96...@qq.com>
AuthorDate: Tue Jul 19 22:55:34 2022 +0800
style: cargo check
---
config/src/config.rs | 5 +--
dubbo/src/echo/echo_client.rs | 50 ++++------------------------
dubbo/src/protocol/grpc/grpc_server.rs | 2 +-
dubbo/src/protocol/triple/triple_exporter.rs | 6 ++++
dubbo/src/protocol/triple/triple_protocol.rs | 6 ++++
triple/src/client/grpc.rs | 4 +--
triple/src/server/decode.rs | 3 +-
triple/src/transport/service.rs | 7 ++--
8 files changed, 29 insertions(+), 54 deletions(-)
diff --git a/config/src/config.rs b/config/src/config.rs
index 771c7ca..a53dcd2 100644
--- a/config/src/config.rs
+++ b/config/src/config.rs
@@ -20,6 +20,7 @@ use std::{any, collections::HashMap};
/// used to storage all structed config, from some source: cmd, file..;
/// Impl Config trait, business init by read Config trait
#[allow(dead_code)]
+#[derive(Debug, Default)]
pub struct RootConfig {
name: String,
data: HashMap<String, Box<dyn any::Any>>,
@@ -53,7 +54,7 @@ impl Config for RootConfig {
None => false,
Some(val) => {
if let Some(v) = val.downcast_ref::<bool>() {
- return *v;
+ *v
} else {
false
}
@@ -66,7 +67,7 @@ impl Config for RootConfig {
None => "".to_string(),
Some(val) => {
if let Some(v) = val.downcast_ref::<String>() {
- return v.into();
+ v.into()
} else {
"".to_string()
}
diff --git a/dubbo/src/echo/echo_client.rs b/dubbo/src/echo/echo_client.rs
index 8db5e89..0f8215b 100644
--- a/dubbo/src/echo/echo_client.rs
+++ b/dubbo/src/echo/echo_client.rs
@@ -13,6 +13,12 @@ pub struct EchoClient {
uri: String,
}
+impl Default for EchoClient {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl EchoClient {
pub fn new() -> Self {
Self {
@@ -29,10 +35,6 @@ impl EchoClient {
self
}
- // pub async fn connect(&self, url: &str) {
- // self.inner.request(req)
- // }
-
pub async fn bidirectional_streaming_echo(
mut self,
req: impl IntoStreamingRequest<Message = HelloRequest>,
@@ -45,44 +47,6 @@ impl EchoClient {
http::uri::PathAndQuery::from_static("/bidi_stream"),
)
.await
- // Stream trait to Body
- // let mut codec = SerdeCodec::<HelloRequest, HelloReply>::default();
- // let stream = req.into_streaming_request();
- // let en = encode(codec.encoder(), stream.into_inner().map(Ok));
- // let body = hyper::Body::wrap_stream(en);
-
- // let req = http::Request::builder()
- // .version(Version::HTTP_2)
- // .uri(self.uri.clone() + "/bidi_stream")
- // .method("POST")
- // .body(body)
- // .unwrap();
-
- // let response = self.inner.request(req).await;
-
- // match response {
- // Ok(v) => {
- // println!("response: {:?}", v);
- // // println!("grpc status: {:?}", v)
- // let mut resp = v.map(|body| Streaming::new(body, codec.decoder()));
- // // TODO: rpc response to http response
- // let trailers_only_status = tonic::Status::from_header_map(resp.headers_mut());
- // println!("trailer only status: {:?}", trailers_only_status);
-
- // let (parts, mut body) = resp.into_parts();
- // let trailer = body.trailer().await.unwrap();
- // println!("trailer: {:?}", trailer);
-
- // // if let Some(trailer) = trailer.take() {
- // // println!("trailer: {:?}", trailer);
- // // }
- // return Ok(Response::new(body));
- // }
- // Err(err) => {
- // println!("error: {}", err);
- // return Err(tonic::Status::new(tonic::Code::Internal, err.to_string()));
- // }
- // }
}
pub async fn say_hello(
@@ -117,7 +81,7 @@ impl EchoClient {
}
Err(err) => {
println!("{}", err);
- return Err(tonic::Status::new(tonic::Code::Internal, err.to_string()));
+ Err(tonic::Status::new(tonic::Code::Internal, err.to_string()))
}
}
}
diff --git a/dubbo/src/protocol/grpc/grpc_server.rs b/dubbo/src/protocol/grpc/grpc_server.rs
index 872257b..b949a55 100644
--- a/dubbo/src/protocol/grpc/grpc_server.rs
+++ b/dubbo/src/protocol/grpc/grpc_server.rs
@@ -34,7 +34,7 @@ pub fn register_greeter_server<T: Greeter>(
server: T,
) -> (super::GrpcBoxCloneService, super::DubboGrpcBox) {
let hello = GreeterServer::<T, GrpcInvoker>::new(server);
- (BoxCloneService::new(hello.clone()), Box::new(hello.clone()))
+ (BoxCloneService::new(hello.clone()), Box::new(hello))
}
// 每个service对应一个Server
diff --git a/dubbo/src/protocol/triple/triple_exporter.rs b/dubbo/src/protocol/triple/triple_exporter.rs
index 5f66863..fcddf79 100644
--- a/dubbo/src/protocol/triple/triple_exporter.rs
+++ b/dubbo/src/protocol/triple/triple_exporter.rs
@@ -10,6 +10,12 @@ impl TripleExporter {
}
}
+impl Default for TripleExporter {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Exporter for TripleExporter {
type InvokerType = TripleInvoker;
diff --git a/dubbo/src/protocol/triple/triple_protocol.rs b/dubbo/src/protocol/triple/triple_protocol.rs
index 876f06c..e3abb48 100644
--- a/dubbo/src/protocol/triple/triple_protocol.rs
+++ b/dubbo/src/protocol/triple/triple_protocol.rs
@@ -12,6 +12,12 @@ pub struct TripleProtocol {
servers: HashMap<String, TripleServer>,
}
+impl Default for TripleProtocol {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl TripleProtocol {
pub fn new() -> Self {
TripleProtocol {
diff --git a/triple/src/client/grpc.rs b/triple/src/client/grpc.rs
index 5126ed1..1277868 100644
--- a/triple/src/client/grpc.rs
+++ b/triple/src/client/grpc.rs
@@ -145,10 +145,10 @@ impl TripleClient {
let resp = v.map(|body| Streaming::new(body, codec.decoder()));
let (_parts, body) = resp.into_parts();
- return Ok(Response::new(body));
+ Ok(Response::new(body))
}
Err(err) => {
- return Err(tonic::Status::new(tonic::Code::Internal, err.to_string()));
+ Err(tonic::Status::new(tonic::Code::Internal, err.to_string()))
}
}
}
diff --git a/triple/src/server/decode.rs b/triple/src/server/decode.rs
index 06ce3ae..3c62aeb 100644
--- a/triple/src/server/decode.rs
+++ b/triple/src/server/decode.rs
@@ -76,8 +76,7 @@ impl<T> Streaming<T> {
// while self.message().await?.is_some() {}
let trailer = future::poll_fn(|cx| Pin::new(&mut self.body).poll_trailers(cx)).await;
- let trailer = trailer.map(|data| data.map(MetadataMap::from_headers));
- trailer
+ trailer.map(|data| data.map(MetadataMap::from_headers))
}
pub fn decode_chunk(&mut self) -> Result<Option<T>, tonic::Status> {
diff --git a/triple/src/transport/service.rs b/triple/src/transport/service.rs
index 8001ef5..e470601 100644
--- a/triple/src/transport/service.rs
+++ b/triple/src/transport/service.rs
@@ -48,7 +48,7 @@ pub struct DubboServer {
impl DubboServer {
pub fn with_accpet_http1(self, accept_http2: bool) -> Self {
Self {
- accept_http2: accept_http2,
+ accept_http2,
..self
}
}
@@ -170,9 +170,8 @@ where
impl BusinessConfig for DubboServer {
fn init() -> Self {
let conf = config::get_global_config();
- let server = DubboServer::new()
- .with_accpet_http1(conf.bool("dubbo.server.accept_http2".to_string()));
- server
+ DubboServer::new()
+ .with_accpet_http1(conf.bool("dubbo.server.accept_http2".to_string()))
}
fn load() -> Result<(), std::convert::Infallible> {