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 21, 2023
1 parent 80fce36 commit 4b2f7ac
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 58 deletions.
55 changes: 30 additions & 25 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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
1 change: 0 additions & 1 deletion volo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
)]
#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]

pub use async_trait::async_trait;
pub use motore::{layer, layer::Layer, service, Service};
pub use tokio::main;

Expand Down
9 changes: 5 additions & 4 deletions volo/src/net/dial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io;
use std::{future::Future, io};

use socket2::{Domain, Protocol, Socket, Type};
#[cfg(target_family = "unix")]
Expand All @@ -15,12 +15,14 @@ use super::{
};

/// [`MakeTransport`] creates an [`AsyncRead`] and an [`AsyncWrite`] for the given [`Address`].
#[async_trait::async_trait]
pub trait MakeTransport: Clone + Send + Sync + 'static {
type ReadHalf: AsyncRead + Send + Sync + Unpin + 'static;
type WriteHalf: AsyncWrite + Send + Sync + Unpin + 'static;

async fn make_transport(&self, addr: Address) -> io::Result<(Self::ReadHalf, Self::WriteHalf)>;
fn make_transport(
&self,
addr: Address,
) -> impl Future<Output = io::Result<(Self::ReadHalf, Self::WriteHalf)>> + Send;
fn set_connect_timeout(&mut self, timeout: Option<Duration>);
fn set_read_timeout(&mut self, timeout: Option<Duration>);
fn set_write_timeout(&mut self, timeout: Option<Duration>);
Expand Down Expand Up @@ -73,7 +75,6 @@ impl DefaultMakeTransport {
}
}

#[async_trait::async_trait]
impl MakeTransport for DefaultMakeTransport {
type ReadHalf = OwnedReadHalf;

Expand Down
Loading

0 comments on commit 4b2f7ac

Please sign in to comment.