A framework that looks most like Rpc, From krpc-rust

The current mainstream Rust-Rpc framework defines IDL and then generates Client calling code through scripts. Compared with the Java implementation version, this is not elegant. This project uses Rust macros to implement compile-time "reflection" to implement an elegant RPC. The framework also supports service registration and discovery.

Quick Start

Server

#[derive(Serialize, Deserialize, Default, Debug)]
struct ReqDto {
    str: String,
}
#[derive(Serialize, Deserialize, Default)]
struct ResDto {
    str: String,
}
#[derive(Clone)]
struct TestServer {
    _db: String,
}

krpc_server! {
   TestServer,
   "1.0.0",
   async fn do_run1(&self,res : ReqDto) -> Result<ResDto> {
      println!("{:?}" ,res);
      return Err("Oh~ an error occurred".to_string());
   }
   async fn do_run2(&self,res : ReqDto) -> Result<ResDto> {
     println!("{:?}" ,res);
     return Ok(ResDto { str : "TestServer say hello 1".to_string()});
    }
}

#[tokio::main(worker_threads = 512)]
async fn main() {
    let server: TestServer = TestServer {
        _db: "I am a DB database".to_string(),
    };

    KrpcServer::build(
        RegisterBuilder::new(
            &format!("127.0.0.1:{}", "2181"),
            "default",
            RegisterType::ZooKeeper,
        ),
        "8081",
    )
    .add_rpc_server(Box::new(server))
    .run()
    .await;
}

Client

lazy_static! {
    static ref CLI: KrpcClient = KrpcClient::build(
        RegisterBuilder::new(
            &format!("127.0.0.1:{}", "2181"),
            "default",
            RegisterType::ZooKeeper,
        )
    );
}
#[derive(Serialize, Deserialize, Default, Debug)]
struct ReqDto {
    str: String,
}
#[derive(Serialize, Deserialize, Default,Debug)]
struct ResDto {
    str: String,
}
struct TestServer;

krpc_client! {
   CLI,
   TestServer,
   "1.0.0",
   async fn do_run1(&self,res : ReqDto) -> Result<ResDto>
   async fn do_run2(&self,res : ReqDto) -> Result<ResDto> 
} 

#[tokio::main(worker_threads = 512)]
async fn main() {
    let client = TestServer;
    let res = client.do_run1(ReqDto{str : "client say hello 1".to_string()}).await;
    println!("{:?}",res);
    let res = client.do_run2(ReqDto{str : "client say hello 2".to_string()}).await;
    println!("{:?}",res);
}