Skip to content

Implementing service in another file #828

Answered by theo-m
theo-m asked this question in Q&A
Discussion options

You must be logged in to vote

I've received pointers from elsewhere:
The solution is to include_proto! only once, e.g. for me

// 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 {}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Ben2146053
Comment options

Answer selected by theo-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants