Skip to content

Commit

Permalink
use nightly version rust to check, format. (apache#111)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
robberphex authored Feb 14, 2023
1 parent 1c0d1c6 commit 59e2ad6
Show file tree
Hide file tree
Showing 40 changed files with 303 additions and 247 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
default: true
- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
Expand Down
2 changes: 2 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ header: # `header` section is configurations for source codes license header.
paths-ignore: # `paths-ignore` are the path list that will be ignored by license-eye.
- '**/*.md'
- '**/Cargo.toml'
- '.rustfmt.toml'
- 'LICENSE'
- 'NOTICE'
- '.asf.yml'
- '.gitignore'
- '.github'
- "**/*.yaml"
- "**/generated/**"
comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.

# license-location-threshold specifies the index threshold where the license header can be located,
Expand Down
4 changes: 4 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unstable_features = true
format_generated_files = false
imports_granularity = "Crate"
reorder_imports = true
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ members = [
"dubbo",
"examples/echo",
"examples/greeter",
"dubbo-build"
"dubbo-build",
]
4 changes: 1 addition & 3 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ use std::{collections::HashMap, env, fs};
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};

use super::protocol::ProtocolConfig;
use super::provider::ProviderConfig;
use super::service::ServiceConfig;
use super::{protocol::ProtocolConfig, provider::ProviderConfig, service::ServiceConfig};

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

Expand Down
10 changes: 7 additions & 3 deletions dubbo-build/src/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use prost_build::{Config, Method, ServiceGenerator};
use quote::ToTokens;
use std::path::{Path, PathBuf};

use crate::client;
use crate::server;
use crate::Attributes;
use crate::{client, server, Attributes};

const PACKAGE_HEADER: &str = "// @generated by apache/dubbo-rust.\n\n";

/// Simple `.proto` compiling. Use [`configure`] instead if you need more options.
///
Expand Down Expand Up @@ -184,6 +184,10 @@ impl ServiceGenerator for SvcGenerator {
self.servers = TokenStream::default();
}
}

fn finalize_package(&mut self, _package: &str, buf: &mut String) {
buf.insert_str(0, PACKAGE_HEADER);
}
}

pub struct DubboService {
Expand Down
21 changes: 12 additions & 9 deletions dubbo/src/cluster/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
* limitations under the License.
*/

use std::collections::HashMap;
use std::fmt::Debug;
use std::str::FromStr;
use std::sync::{Arc, RwLock};

use crate::common::url::Url;
use crate::invocation::{Invocation, RpcInvocation};
use crate::registry::memory_registry::MemoryNotifyListener;
use crate::registry::{BoxRegistry, RegistryWrapper};
use std::{
collections::HashMap,
fmt::Debug,
str::FromStr,
sync::{Arc, RwLock},
};

use crate::{
common::url::Url,
invocation::{Invocation, RpcInvocation},
registry::{memory_registry::MemoryNotifyListener, BoxRegistry, RegistryWrapper},
};

/// Directory.
///
Expand Down
52 changes: 28 additions & 24 deletions dubbo/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,39 @@
* limitations under the License.
*/

pub use std::sync::Arc;
pub use std::task::{Context, Poll};
pub use std::{
sync::Arc,
task::{Context, Poll},
};

pub use async_trait::async_trait;
pub use bytes::Bytes;
pub use http_body::Body;
pub use hyper::Body as hyperBody;
pub use tower_service::Service;

pub use super::cluster::directory::Directory;
pub use super::cluster::directory::RegistryDirectory;
pub use super::invocation::RpcInvocation;
pub use super::invocation::{IntoStreamingRequest, Request, Response};
pub use super::protocol::triple::triple_invoker::TripleInvoker;
pub use super::protocol::Invoker;
pub use super::registry::BoxRegistry;
pub use super::registry::Registry;
pub use super::registry::RegistryWrapper;
pub use super::triple::client::TripleClient;
pub use super::triple::codec::prost::ProstCodec;
pub use super::triple::codec::Codec;
pub use super::triple::decode::Decoding;
pub use super::triple::server::service::{
ClientStreamingSvc, ServerStreamingSvc, StreamingSvc, UnarySvc,
pub use super::{
cluster::directory::{Directory, RegistryDirectory},
empty_body,
invocation::{IntoStreamingRequest, Request, Response, RpcInvocation},
protocol::{triple::triple_invoker::TripleInvoker, Invoker},
registry::{BoxRegistry, Registry, RegistryWrapper},
triple::{
client::TripleClient,
codec::{prost::ProstCodec, Codec},
decode::Decoding,
server::{
service::{ClientStreamingSvc, ServerStreamingSvc, StreamingSvc, UnarySvc},
TripleServer,
},
},
BoxBody, BoxFuture, StdError,
};
pub use crate::{
filter::{service::FilterService, Filter},
triple::{
client::builder::{ClientBoxService, ClientBuilder},
server::builder::ServerBuilder,
transport::connection::Connection,
},
};
pub use super::triple::server::TripleServer;
pub use super::{empty_body, BoxBody, BoxFuture, StdError};
pub use crate::filter::service::FilterService;
pub use crate::filter::Filter;
pub use crate::triple::client::builder::{ClientBoxService, ClientBuilder};
pub use crate::triple::server::builder::ServerBuilder;
pub use crate::triple::transport::connection::Connection;
8 changes: 5 additions & 3 deletions dubbo/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
* limitations under the License.
*/

use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::thread;
use std::{
collections::HashMap,
sync::{Arc, Mutex},
thread,
};

use serde_json::Value;
use state::Container;
Expand Down
3 changes: 1 addition & 2 deletions dubbo/src/filter/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
use tower_service::Service;

use super::Filter;
use crate::invocation::Metadata;
use crate::invocation::Request;
use crate::invocation::{Metadata, Request};

#[derive(Clone)]
pub struct FilterService<S, F> {
Expand Down
14 changes: 7 additions & 7 deletions dubbo/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* limitations under the License.
*/

use std::collections::HashMap;
use std::pin::Pin;
use std::{collections::HashMap, pin::Pin};

use futures::future;
use futures::Future;
use futures::{future, Future};

use crate::common::url::Url;
use crate::protocol::{BoxExporter, Protocol};
use crate::registry::protocol::RegistryProtocol;
use crate::{
common::url::Url,
protocol::{BoxExporter, Protocol},
registry::protocol::RegistryProtocol,
};
use dubbo_config::{get_global_config, RootConfig};

// Invoker是否可以基于hyper写一个通用的
Expand Down
3 changes: 1 addition & 2 deletions dubbo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub mod triple;
pub mod utils;

use http_body::Body;
use std::future::Future;
use std::pin::Pin;
use std::{future::Future, pin::Pin};

pub use framework::Dubbo;

Expand Down
6 changes: 4 additions & 2 deletions dubbo/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
pub mod server_desc;
pub mod triple;

use std::future::Future;
use std::task::{Context, Poll};
use std::{
future::Future,
task::{Context, Poll},
};

use async_trait::async_trait;
use tower_service::Service;
Expand Down
6 changes: 2 additions & 4 deletions dubbo/src/protocol/triple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ pub mod triple_protocol;
pub mod triple_server;

use lazy_static::lazy_static;
use std::collections::HashMap;
use std::sync::RwLock;
use std::{collections::HashMap, sync::RwLock};

use crate::utils::boxed_clone::BoxCloneService;
use crate::BoxBody;
use crate::{utils::boxed_clone::BoxCloneService, BoxBody};

pub type GrpcBoxCloneService =
BoxCloneService<http::Request<hyper::Body>, http::Response<BoxBody>, std::convert::Infallible>;
Expand Down
4 changes: 1 addition & 3 deletions dubbo/src/protocol/triple/triple_invoker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

use tower_service::Service;

use crate::common::url::Url;
use crate::protocol::Invoker;
use crate::triple::client::builder::ClientBoxService;
use crate::{common::url::Url, protocol::Invoker, triple::client::builder::ClientBoxService};

pub struct TripleInvoker {
url: Url,
Expand Down
15 changes: 8 additions & 7 deletions dubbo/src/protocol/triple/triple_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
* limitations under the License.
*/

use std::boxed::Box;
use std::collections::HashMap;
use std::{boxed::Box, collections::HashMap};

use async_trait::async_trait;

use super::triple_exporter::TripleExporter;
use super::triple_invoker::TripleInvoker;
use super::triple_server::TripleServer;
use crate::common::url::Url;
use crate::protocol::{BoxExporter, Protocol};
use super::{
triple_exporter::TripleExporter, triple_invoker::TripleInvoker, triple_server::TripleServer,
};
use crate::{
common::url::Url,
protocol::{BoxExporter, Protocol},
};

#[derive(Clone)]
pub struct TripleProtocol {
Expand Down
7 changes: 4 additions & 3 deletions dubbo/src/registry/memory_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/

#![allow(unused_variables, dead_code, missing_docs)]
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::RwLock;
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};

use crate::common::url::Url;

Expand Down
22 changes: 12 additions & 10 deletions dubbo/src/registry/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
* limitations under the License.
*/

use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};

use super::memory_registry::MemoryRegistry;
use super::BoxRegistry;
use crate::common::url::Url;
use crate::protocol::triple::triple_exporter::TripleExporter;
use crate::protocol::triple::triple_protocol::TripleProtocol;
use crate::protocol::BoxExporter;
use crate::protocol::BoxInvoker;
use crate::protocol::Protocol;
use super::{memory_registry::MemoryRegistry, BoxRegistry};
use crate::{
common::url::Url,
protocol::{
triple::{triple_exporter::TripleExporter, triple_protocol::TripleProtocol},
BoxExporter, BoxInvoker, Protocol,
},
};

#[derive(Clone, Default)]
pub struct RegistryProtocol {
Expand Down
3 changes: 1 addition & 2 deletions dubbo/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* limitations under the License.
*/

use std::error::Error;
use std::fmt;
use std::{error::Error, fmt};

use http::HeaderValue;

Expand Down
8 changes: 4 additions & 4 deletions dubbo/src/triple/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

use crate::cluster::directory::StaticDirectory;
use crate::codegen::Directory;
use crate::triple::compression::CompressionEncoding;
use crate::utils::boxed::BoxService;
use crate::{
cluster::directory::StaticDirectory, codegen::Directory,
triple::compression::CompressionEncoding, utils::boxed::BoxService,
};

use super::TripleClient;

Expand Down
12 changes: 5 additions & 7 deletions dubbo/src/triple/client/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ use http::HeaderValue;
use rand::prelude::SliceRandom;
use tower_service::Service;

use super::super::transport::connection::Connection;
use super::builder::ClientBuilder;
use super::{super::transport::connection::Connection, builder::ClientBuilder};
use crate::codegen::{Directory, RpcInvocation};

use crate::invocation::{IntoStreamingRequest, Metadata, Request, Response};
use crate::triple::codec::Codec;
use crate::triple::compression::CompressionEncoding;
use crate::triple::decode::Decoding;
use crate::triple::encode::encode;
use crate::{
invocation::{IntoStreamingRequest, Metadata, Request, Response},
triple::{codec::Codec, compression::CompressionEncoding, decode::Decoding, encode::encode},
};

#[derive(Debug, Clone, Default)]
pub struct TripleClient {
Expand Down
3 changes: 1 addition & 2 deletions dubbo/src/triple/codec/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* limitations under the License.
*/

use bytes::buf::UninitSlice;
use bytes::{Buf, BufMut, BytesMut};
use bytes::{buf::UninitSlice, Buf, BufMut, BytesMut};

/// A specialized buffer to decode gRPC messages from.
#[derive(Debug)]
Expand Down
6 changes: 4 additions & 2 deletions dubbo/src/triple/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
use std::collections::HashMap;

use bytes::{Buf, BufMut, BytesMut};
use flate2::read::{GzDecoder, GzEncoder};
use flate2::Compression;
use flate2::{
read::{GzDecoder, GzEncoder},
Compression,
};
use lazy_static::lazy_static;

pub const GRPC_ACCEPT_ENCODING: &str = "grpc-accept-encoding";
Expand Down
Loading

0 comments on commit 59e2ad6

Please sign in to comment.