Skip to content

Commit

Permalink
feat: use afit to optimize gen code
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWhiteWu committed Oct 23, 2023
1 parent 80fce36 commit 1c8219d
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 66 deletions.
64 changes: 34 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ repository = "https://github.com/cloudwego/volo"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
# pilota = "0.8"
# pilota-build = "0.8"
# pilota-thrift-parser = "0.4"
# pilota = "0.9"
# pilota-build = "0.9"
# pilota-thrift-parser = "0.9"
pilota = { git = "https://github.com/cloudwego/pilota", branch = "main" }
pilota-build = { git = "https://github.com/cloudwego/pilota", branch = "main" }
pilota-thrift-parser = { git = "https://github.com/cloudwego/pilota", branch = "main" }
Expand All @@ -36,7 +36,6 @@ metainfo = "0.7"
anyhow = "1"
async-broadcast = "0.6"
async-stream = "0.3"
async-trait = "0.1"
base64 = "0.13"
bytes = "1"
chrono = { version = "0.4", default-features = false, features = [
Expand Down
1 change: 0 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ path = "src/unknown/thrift_client.rs"
[dependencies]
anyhow.workspace = true
async-stream.workspace = true
async-trait.workspace = true
lazy_static.workspace = true
metainfo.workspace = true
tokio = { workspace = true, features = ["full"] }
Expand Down
1 change: 0 additions & 1 deletion examples/src/compression/grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use volo_grpc::{

pub struct S;

#[volo::async_trait]
impl volo_gen::proto_gen::hello::Greeter for S {
async fn say_hello(
&self,
Expand Down
1 change: 0 additions & 1 deletion examples/src/hello/grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use volo_grpc::server::{Server, ServiceBuilder};

pub struct S;

#[volo::async_trait]
impl volo_gen::proto_gen::hello::Greeter for S {
async fn say_hello(
&self,
Expand Down
1 change: 0 additions & 1 deletion examples/src/hello/thrift_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::net::SocketAddr;

pub struct S;

#[volo::async_trait]
impl volo_gen::thrift_gen::hello::HelloService for S {
async fn hello(
&self,
Expand Down
1 change: 0 additions & 1 deletion examples/src/loadbalance/grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ impl S {
}
}

#[volo::async_trait]
impl volo_gen::proto_gen::hello::Greeter for S {
async fn say_hello(
&self,
Expand Down
2 changes: 0 additions & 2 deletions examples/src/multiplex/grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use volo_grpc::server::{Server, ServiceBuilder};

pub struct G;

#[volo::async_trait]
impl volo_gen::proto_gen::hello::Greeter for G {
async fn say_hello(
&self,
Expand All @@ -20,7 +19,6 @@ impl volo_gen::proto_gen::hello::Greeter for G {

pub struct E;

#[volo::async_trait]
impl volo_gen::proto_gen::echo::Echo for E {
async fn echo(
&self,
Expand Down
1 change: 0 additions & 1 deletion examples/src/streaming/grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use volo_grpc::{

pub struct S;

#[volo::async_trait]
impl volo_gen::proto_gen::streaming::Streaming for S {
async fn unary(
&self,
Expand Down
1 change: 0 additions & 1 deletion examples/src/unknown/thrift_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::net::SocketAddr;

pub struct S;

#[volo::async_trait]
impl volo_gen::thrift_gen::echo_unknown::EchoService for S {
async fn hello(
&self,
Expand Down
1 change: 0 additions & 1 deletion examples/volo-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ publish = false

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
futures.workspace = true
tokio = { workspace = true, features = ["full"] }

Expand Down
1 change: 0 additions & 1 deletion volo-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ volo = { version = "0.8", path = "../volo" }
pilota-build.workspace = true

anyhow.workspace = true
async-trait.workspace = true
dirs.workspace = true
heck.workspace = true
itertools.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion volo-build/src/grpc_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,10 @@ impl CodegenBackend for VoloGrpcBackend {

let name = self.cx().rust_name(method.def_id);

format!("async fn {name}(&self, {args}) -> ::std::result::Result<{ret_ty}>;")
format!(
"fn {name}(&self, {args}) -> impl ::std::future::Future<Output = \
::std::result::Result<{ret_ty}>> + Send;"
)
}

fn codegen_service_method_with_global_path(
Expand Down
5 changes: 4 additions & 1 deletion volo-build/src/thrift_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,10 @@ impl pilota_build::CodegenBackend for VoloThriftBackend {
"::volo_thrift::AnyhowError".into()
};

format!("async fn {name}(&self, {args}) -> ::core::result::Result<{ret_ty}, {exception}>;")
format!(
"fn {name}(&self, {args}) -> impl ::std::future::Future<Output = \
::core::result::Result<{ret_ty}, {exception}>> + Send;"
)
}

fn codegen_service_method_with_global_path(
Expand Down
1 change: 0 additions & 1 deletion volo-cli/src/templates/grpc/src/lib_rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pub struct S;

#[volo::async_trait]
impl volo_gen::{service_global_name} for S {{
{methods}
}}
1 change: 0 additions & 1 deletion volo-cli/src/templates/thrift/src/lib_rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pub struct S;

#[volo::async_trait]
impl volo_gen::{service_global_name} for S {{
{methods}
}}
1 change: 0 additions & 1 deletion volo-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ metainfo.workspace = true

anyhow.workspace = true
async-stream.workspace = true
async-trait.workspace = true
base64.workspace = true
bytes.workspace = true
fxhash.workspace = true
Expand Down
1 change: 0 additions & 1 deletion volo-thrift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ motore.workspace = true
metainfo.workspace = true

anyhow.workspace = true
async-trait.workspace = true
bytes.workspace = true
chrono.workspace = true
futures.workspace = true
Expand Down
1 change: 1 addition & 0 deletions volo-thrift/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl From<DecodeError> for Error {
pilota::thrift::ProtocolErrorKind::Unknown,
value.to_string(),
)),
pilota::thrift::DecodeErrorKind::Unknown => protocol_err!(Unknown),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion volo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ maintenance = { status = "actively-developed" }
motore.workspace = true

async-broadcast.workspace = true
async-trait.workspace = true
dashmap.workspace = true
faststr.workspace = true
futures.workspace = true
Expand Down
Loading

0 comments on commit 1c8219d

Please sign in to comment.