Skip to content

codegen: call handlers through the service trait - #324

Draft
iainmcgin wants to merge 1 commit into
mainfrom
iain/rpc-register-collision
Draft

iainmcgin wants to merge 1 commit into
mainfrom
iain/rpc-register-collision

Conversation

@iainmcgin

Copy link
Copy Markdown
Collaborator

A service with rpc Register(...) does not compile: generated server code calls svc.register(ctx, req) on an Arc<S>, which resolves to the generated extension method register(self: Arc<Self>, router). The same happens for any RPC whose Rust name is a prelude trait method that Arc implements, such as clone, into, try_into, to_owned, as_ref and drop.

Generated code now calls Trait::method(&*svc, ctx, request), in both the Router registration and the monomorphic dispatcher. For an existing service this is the call that method syntax already resolved to, with one exception: if the service trait is implemented for Arc<X> as well as for X, the generated code now calls X's handler.

This makes client methods named clone, into and try_into reachable for the first time, and method-call syntax does not reach all of them: client.into(req) resolves to Into::into. A follow-up PR will name these client methods with a trailing underscore. It should land before the next release, because renaming them after a release is a breaking change.

Fixes #309

Generated server code called each handler with method-call syntax on
the `Arc` that holds the service. An RPC whose Rust name is also a
method of that `Arc` resolved to the wrong method and failed to
compile: the generated `register`, or a prelude trait method such as
`clone`, `into` or `drop`. Generated code now calls
`Trait::method(&*svc, ctx, request)`.

An RPC named `New`, `Config` or `ConfigMut` still does not compile,
because the generated client has methods with those names.

Fixes #309

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Iain McGinniss <309153+iainmcgin@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rpc method "register" causes name conflict

1 participant