Skip to content

Multiple Service Definition Traits #499

@MohenjoDaro

Description

@MohenjoDaro

Having multiple service definition traits on a single server/listener doesn't seem to be supported, though there's nothing mentioned about it in the docs. Basically adding a additional trait like this to the lib

#[tarpc::service]
pub trait Ping {
    /// Returns a greeting for name.
    async fn ping() -> Result<(), String>;
}

and adding it to the server as well like

impl Check for HelloServer {
    async fn ping(self, _: context::Context) -> Result<(), String> {
        Ok(())
    }
}

will cause an error with the serve() code since it doesn't know which trait you want to serve unless you specify. This can cause weird behaviors where having the same function in service definition A and B only calls the function in A and never B, or a function in B failing because it doesn't exist in A, and the server is serving A and not B. And since the function is named .serve() for all the service definitions, it's hard to tell which one if being served by the listener when looking at the code

I don't know if this is actually an issue/bug or not, whether it's gone unnoticed so far, or what. But, I thought I'd bring it up since it doesn't appear to be mentioned in the docs, and took me awhile to figure out this was the cause of my problem since I have my service definitions spread out more than I should it seems

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions