Skip to content

Commit 59e2ad6

Browse files
authored
use nightly version rust to check, format. (#111)
* 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 * rustfmt * use nightly version to check * format * generated * .licenserc.yaml
1 parent 1c0d1c6 commit 59e2ad6

40 files changed

+303
-247
lines changed

.github/workflows/github-actions.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
- uses: actions/checkout@main
2323
- uses: actions-rs/toolchain@v1
2424
with:
25-
toolchain: stable
25+
toolchain: nightly
26+
default: true
2627
- name: Set up cargo cache
2728
uses: actions/cache@v3
2829
continue-on-error: false

.licenserc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ header: # `header` section is configurations for source codes license header.
5656
paths-ignore: # `paths-ignore` are the path list that will be ignored by license-eye.
5757
- '**/*.md'
5858
- '**/Cargo.toml'
59+
- '.rustfmt.toml'
5960
- 'LICENSE'
6061
- 'NOTICE'
6162
- '.asf.yml'
6263
- '.gitignore'
6364
- '.github'
6465
- "**/*.yaml"
66+
- "**/generated/**"
6567
comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.
6668

6769
# license-location-threshold specifies the index threshold where the license header can be located,

.rustfmt.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
unstable_features = true
2+
format_generated_files = false
3+
imports_granularity = "Crate"
4+
reorder_imports = true

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ members = [
99
"dubbo",
1010
"examples/echo",
1111
"examples/greeter",
12-
"dubbo-build"
12+
"dubbo-build",
1313
]

config/src/config.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use std::{collections::HashMap, env, fs};
2020
use once_cell::sync::OnceCell;
2121
use serde::{Deserialize, Serialize};
2222

23-
use super::protocol::ProtocolConfig;
24-
use super::provider::ProviderConfig;
25-
use super::service::ServiceConfig;
23+
use super::{protocol::ProtocolConfig, provider::ProviderConfig, service::ServiceConfig};
2624

2725
pub const DUBBO_CONFIG_PATH: &str = "./dubbo.yaml";
2826

dubbo-build/src/prost.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use prost_build::{Config, Method, ServiceGenerator};
2020
use quote::ToTokens;
2121
use std::path::{Path, PathBuf};
2222

23-
use crate::client;
24-
use crate::server;
25-
use crate::Attributes;
23+
use crate::{client, server, Attributes};
24+
25+
const PACKAGE_HEADER: &str = "// @generated by apache/dubbo-rust.\n\n";
2626

2727
/// Simple `.proto` compiling. Use [`configure`] instead if you need more options.
2828
///
@@ -184,6 +184,10 @@ impl ServiceGenerator for SvcGenerator {
184184
self.servers = TokenStream::default();
185185
}
186186
}
187+
188+
fn finalize_package(&mut self, _package: &str, buf: &mut String) {
189+
buf.insert_str(0, PACKAGE_HEADER);
190+
}
187191
}
188192

189193
pub struct DubboService {

dubbo/src/cluster/directory.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
* limitations under the License.
1616
*/
1717

18-
use std::collections::HashMap;
19-
use std::fmt::Debug;
20-
use std::str::FromStr;
21-
use std::sync::{Arc, RwLock};
22-
23-
use crate::common::url::Url;
24-
use crate::invocation::{Invocation, RpcInvocation};
25-
use crate::registry::memory_registry::MemoryNotifyListener;
26-
use crate::registry::{BoxRegistry, RegistryWrapper};
18+
use std::{
19+
collections::HashMap,
20+
fmt::Debug,
21+
str::FromStr,
22+
sync::{Arc, RwLock},
23+
};
24+
25+
use crate::{
26+
common::url::Url,
27+
invocation::{Invocation, RpcInvocation},
28+
registry::{memory_registry::MemoryNotifyListener, BoxRegistry, RegistryWrapper},
29+
};
2730

2831
/// Directory.
2932
///

dubbo/src/codegen.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,39 @@
1515
* limitations under the License.
1616
*/
1717

18-
pub use std::sync::Arc;
19-
pub use std::task::{Context, Poll};
18+
pub use std::{
19+
sync::Arc,
20+
task::{Context, Poll},
21+
};
2022

2123
pub use async_trait::async_trait;
2224
pub use bytes::Bytes;
2325
pub use http_body::Body;
2426
pub use hyper::Body as hyperBody;
2527
pub use tower_service::Service;
2628

27-
pub use super::cluster::directory::Directory;
28-
pub use super::cluster::directory::RegistryDirectory;
29-
pub use super::invocation::RpcInvocation;
30-
pub use super::invocation::{IntoStreamingRequest, Request, Response};
31-
pub use super::protocol::triple::triple_invoker::TripleInvoker;
32-
pub use super::protocol::Invoker;
33-
pub use super::registry::BoxRegistry;
34-
pub use super::registry::Registry;
35-
pub use super::registry::RegistryWrapper;
36-
pub use super::triple::client::TripleClient;
37-
pub use super::triple::codec::prost::ProstCodec;
38-
pub use super::triple::codec::Codec;
39-
pub use super::triple::decode::Decoding;
40-
pub use super::triple::server::service::{
41-
ClientStreamingSvc, ServerStreamingSvc, StreamingSvc, UnarySvc,
29+
pub use super::{
30+
cluster::directory::{Directory, RegistryDirectory},
31+
empty_body,
32+
invocation::{IntoStreamingRequest, Request, Response, RpcInvocation},
33+
protocol::{triple::triple_invoker::TripleInvoker, Invoker},
34+
registry::{BoxRegistry, Registry, RegistryWrapper},
35+
triple::{
36+
client::TripleClient,
37+
codec::{prost::ProstCodec, Codec},
38+
decode::Decoding,
39+
server::{
40+
service::{ClientStreamingSvc, ServerStreamingSvc, StreamingSvc, UnarySvc},
41+
TripleServer,
42+
},
43+
},
44+
BoxBody, BoxFuture, StdError,
45+
};
46+
pub use crate::{
47+
filter::{service::FilterService, Filter},
48+
triple::{
49+
client::builder::{ClientBoxService, ClientBuilder},
50+
server::builder::ServerBuilder,
51+
transport::connection::Connection,
52+
},
4253
};
43-
pub use super::triple::server::TripleServer;
44-
pub use super::{empty_body, BoxBody, BoxFuture, StdError};
45-
pub use crate::filter::service::FilterService;
46-
pub use crate::filter::Filter;
47-
pub use crate::triple::client::builder::{ClientBoxService, ClientBuilder};
48-
pub use crate::triple::server::builder::ServerBuilder;
49-
pub use crate::triple::transport::connection::Connection;

dubbo/src/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
* limitations under the License.
1616
*/
1717

18-
use std::collections::HashMap;
19-
use std::sync::{Arc, Mutex};
20-
use std::thread;
18+
use std::{
19+
collections::HashMap,
20+
sync::{Arc, Mutex},
21+
thread,
22+
};
2123

2224
use serde_json::Value;
2325
use state::Container;

dubbo/src/filter/service.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
use tower_service::Service;
1919

2020
use super::Filter;
21-
use crate::invocation::Metadata;
22-
use crate::invocation::Request;
21+
use crate::invocation::{Metadata, Request};
2322

2423
#[derive(Clone)]
2524
pub struct FilterService<S, F> {

dubbo/src/framework.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18-
use std::collections::HashMap;
19-
use std::pin::Pin;
18+
use std::{collections::HashMap, pin::Pin};
2019

21-
use futures::future;
22-
use futures::Future;
20+
use futures::{future, Future};
2321

24-
use crate::common::url::Url;
25-
use crate::protocol::{BoxExporter, Protocol};
26-
use crate::registry::protocol::RegistryProtocol;
22+
use crate::{
23+
common::url::Url,
24+
protocol::{BoxExporter, Protocol},
25+
registry::protocol::RegistryProtocol,
26+
};
2727
use dubbo_config::{get_global_config, RootConfig};
2828

2929
// Invoker是否可以基于hyper写一个通用的

dubbo/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub mod triple;
2929
pub mod utils;
3030

3131
use http_body::Body;
32-
use std::future::Future;
33-
use std::pin::Pin;
32+
use std::{future::Future, pin::Pin};
3433

3534
pub use framework::Dubbo;
3635

dubbo/src/protocol/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
pub mod server_desc;
1919
pub mod triple;
2020

21-
use std::future::Future;
22-
use std::task::{Context, Poll};
21+
use std::{
22+
future::Future,
23+
task::{Context, Poll},
24+
};
2325

2426
use async_trait::async_trait;
2527
use tower_service::Service;

dubbo/src/protocol/triple/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ pub mod triple_protocol;
2121
pub mod triple_server;
2222

2323
use lazy_static::lazy_static;
24-
use std::collections::HashMap;
25-
use std::sync::RwLock;
24+
use std::{collections::HashMap, sync::RwLock};
2625

27-
use crate::utils::boxed_clone::BoxCloneService;
28-
use crate::BoxBody;
26+
use crate::{utils::boxed_clone::BoxCloneService, BoxBody};
2927

3028
pub type GrpcBoxCloneService =
3129
BoxCloneService<http::Request<hyper::Body>, http::Response<BoxBody>, std::convert::Infallible>;

dubbo/src/protocol/triple/triple_invoker.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
use tower_service::Service;
1919

20-
use crate::common::url::Url;
21-
use crate::protocol::Invoker;
22-
use crate::triple::client::builder::ClientBoxService;
20+
use crate::{common::url::Url, protocol::Invoker, triple::client::builder::ClientBoxService};
2321

2422
pub struct TripleInvoker {
2523
url: Url,

dubbo/src/protocol/triple/triple_protocol.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
* limitations under the License.
1616
*/
1717

18-
use std::boxed::Box;
19-
use std::collections::HashMap;
18+
use std::{boxed::Box, collections::HashMap};
2019

2120
use async_trait::async_trait;
2221

23-
use super::triple_exporter::TripleExporter;
24-
use super::triple_invoker::TripleInvoker;
25-
use super::triple_server::TripleServer;
26-
use crate::common::url::Url;
27-
use crate::protocol::{BoxExporter, Protocol};
22+
use super::{
23+
triple_exporter::TripleExporter, triple_invoker::TripleInvoker, triple_server::TripleServer,
24+
};
25+
use crate::{
26+
common::url::Url,
27+
protocol::{BoxExporter, Protocol},
28+
};
2829

2930
#[derive(Clone)]
3031
pub struct TripleProtocol {

dubbo/src/registry/memory_registry.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*/
1717

1818
#![allow(unused_variables, dead_code, missing_docs)]
19-
use std::collections::HashMap;
20-
use std::sync::Arc;
21-
use std::sync::RwLock;
19+
use std::{
20+
collections::HashMap,
21+
sync::{Arc, RwLock},
22+
};
2223

2324
use crate::common::url::Url;
2425

dubbo/src/registry/protocol.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
* limitations under the License.
1616
*/
1717

18-
use std::collections::HashMap;
19-
use std::sync::{Arc, RwLock};
18+
use std::{
19+
collections::HashMap,
20+
sync::{Arc, RwLock},
21+
};
2022

21-
use super::memory_registry::MemoryRegistry;
22-
use super::BoxRegistry;
23-
use crate::common::url::Url;
24-
use crate::protocol::triple::triple_exporter::TripleExporter;
25-
use crate::protocol::triple::triple_protocol::TripleProtocol;
26-
use crate::protocol::BoxExporter;
27-
use crate::protocol::BoxInvoker;
28-
use crate::protocol::Protocol;
23+
use super::{memory_registry::MemoryRegistry, BoxRegistry};
24+
use crate::{
25+
common::url::Url,
26+
protocol::{
27+
triple::{triple_exporter::TripleExporter, triple_protocol::TripleProtocol},
28+
BoxExporter, BoxInvoker, Protocol,
29+
},
30+
};
2931

3032
#[derive(Clone, Default)]
3133
pub struct RegistryProtocol {

dubbo/src/status.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
use std::error::Error;
19-
use std::fmt;
18+
use std::{error::Error, fmt};
2019

2120
use http::HeaderValue;
2221

dubbo/src/triple/client/builder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
use crate::cluster::directory::StaticDirectory;
19-
use crate::codegen::Directory;
20-
use crate::triple::compression::CompressionEncoding;
21-
use crate::utils::boxed::BoxService;
18+
use crate::{
19+
cluster::directory::StaticDirectory, codegen::Directory,
20+
triple::compression::CompressionEncoding, utils::boxed::BoxService,
21+
};
2222

2323
use super::TripleClient;
2424

dubbo/src/triple/client/triple.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ use http::HeaderValue;
2323
use rand::prelude::SliceRandom;
2424
use tower_service::Service;
2525

26-
use super::super::transport::connection::Connection;
27-
use super::builder::ClientBuilder;
26+
use super::{super::transport::connection::Connection, builder::ClientBuilder};
2827
use crate::codegen::{Directory, RpcInvocation};
2928

30-
use crate::invocation::{IntoStreamingRequest, Metadata, Request, Response};
31-
use crate::triple::codec::Codec;
32-
use crate::triple::compression::CompressionEncoding;
33-
use crate::triple::decode::Decoding;
34-
use crate::triple::encode::encode;
29+
use crate::{
30+
invocation::{IntoStreamingRequest, Metadata, Request, Response},
31+
triple::{codec::Codec, compression::CompressionEncoding, decode::Decoding, encode::encode},
32+
};
3533

3634
#[derive(Debug, Clone, Default)]
3735
pub struct TripleClient {

dubbo/src/triple/codec/buffer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
use bytes::buf::UninitSlice;
19-
use bytes::{Buf, BufMut, BytesMut};
18+
use bytes::{buf::UninitSlice, Buf, BufMut, BytesMut};
2019

2120
/// A specialized buffer to decode gRPC messages from.
2221
#[derive(Debug)]

dubbo/src/triple/compression.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
use std::collections::HashMap;
1919

2020
use bytes::{Buf, BufMut, BytesMut};
21-
use flate2::read::{GzDecoder, GzEncoder};
22-
use flate2::Compression;
21+
use flate2::{
22+
read::{GzDecoder, GzEncoder},
23+
Compression,
24+
};
2325
use lazy_static::lazy_static;
2426

2527
pub const GRPC_ACCEPT_ENCODING: &str = "grpc-accept-encoding";

0 commit comments

Comments
 (0)