-
Hello, # main.rs
use tonic::transport::Server;
use pb::user_service_server::UserServiceServer;
use pb::user_service_server::UserService;
use user::UserServiceImpl;
mod user;
mod pb {
tonic::include_proto!("app");
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:50051".parse()?;
let user_service = UserServiceImpl::default();
Server::builder()
.add_service(UserServiceServer::new(user_service))
.serve(addr)
.await?;
Ok(())
} and next to it another file responsible for the implementation of the # user.rs
use tonic::{Request, Response, Status};
mod pb {
tonic::include_proto!("app");
}
#[derive(Debug, Default)]
pub struct UserServiceImpl {}
#[tonic::async_trait]
impl pb::user_service_server::UserService for UserServiceImpl {
async fn sync_contacts(
&self,
request: Request<pb::SyncContactsInput>,
) -> Result<Response<pb::SyncContactsOutput>, Status> {
unimplemented!()
}
async fn onboarding(
&self,
request: Request<pb::OnboardingInput>,
) -> Result<Response<pb::MeUser>, Status> {
unimplemented!()
}
async fn me(
&self,
request: Request<pb::Empty>,
) -> Result<Response<pb::MeUser>, Status> {
unimplemented!()
}
async fn get(
&self,
request: Request<pb::UserGetInput>,
) -> Result<Response<pb::User>, Status> {
unimplemented!()
}
} But compiling fails with:
I've been looking around and saw different solutions on stackoverflow but none made my program compile. In the current state concatening the content of the two files is a compiling program. Could not find examples of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I've received pointers from elsewhere: // main.rs
use tonic::transport::Server;
use pb::user_service_server::UserServiceServer;
use pb::user_service_server::UserService;
use user::UserServiceImpl;
mod user;
use user::pb;
// don't do this!
// mod pb {
// tonic::include_proto!("app");
// } // user.rs
use tonic::{Request, Response, Status};
// v--- make the thing public! ---v
pub mod pb {
tonic::include_proto!("app");
}
#[derive(Debug, Default)]
pub struct UserServiceImpl {} |
Beta Was this translation helpful? Give feedback.
I've received pointers from elsewhere:
The solution is to
include_proto!
only once, e.g. for me