Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Dereference the Arc before calling methods on the interface #142

Closed
wants to merge 1 commit into from

Conversation

yonran
Copy link
Contributor

@yonran yonran commented Dec 29, 2018

When calling methods on Arc<MyService> where the method is also defined on Arc (e.g. drop and clone), calling handler_copy.method(o, p) will actually attempt to call the Arc method instead of the method on the service, resulting in a compiler error. This change removes the ambiguity by dereferencing the Arc.

// proto file:
message DropReq {}
message DropResp {}
service HelloService {
    rpc Drop (DropReq) returns (DropResp);
    rpc Clone (DropReq) returns (DropResp);
}
// Generated _grpc.rs file:
// server
impl HelloServiceServer {
    pub fn new_service_def<H : HelloService + 'static + Sync + Send + 'static>(handler: H) -> ::grpc::rt::ServerServiceDefinition {::grpc::rt::MethodHandlerUnary::new(move |o, p| handler_copy.drop(o, p))
        // compiler error: explicit destructor calls not allowed
        // compiler error: expected 0 parameters
        // compiler error: expected struct `grpc::resp::SingleResponse`, found ()
    }
}

An alternative fix would be to use the fully qualified syntax for method calls (yonran@d5d7f4c). I believe that this change should be good enough because H is only known to be H : HelloService + 'static + Sync + Send + 'static, and Sync and Send define no other methods.

When calling methods on Arc<MyService> where the method is also defined on Arc (e.g. drop and clone), calling handler_copy.method(o, p) will actually attempt to call the Arc method instead of the method on the service, resulting in a compiler error. This change removes the ambiguity by dereferencing the Arc.
@stepancheg
Copy link
Owner

Merged as aafba06.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants