-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve service server ergonomics #373
base: main
Are you sure you want to change the base?
Conversation
4522c98
to
68b0ef5
Compare
I've been planning on doing something similar to this, but I think we can take it even further and make it so that rclrs can infer the service type without the user explicitly stating it. First we would introduce a new trait to
That trait would get automatically generated by Then we can introduce a convenience struct to help with destructuring the callback argument:
Then we can change the signature of
Then users can create a service like this:
I tried to come up with a way to allow this with the same function signature, like so:
but I don't think it's possible until the Rust language can support specialization for generics. Anyway, I think the key benefit to my recommendation is that
Here is a link to a Rust playground that prototypes my recommendations. |
On a separate note, I strongly urge us to keep the signature of services as |
After more thought, I've decided that my previous suggestion that involved introducing more traits wouldn't accomplish much. But I do think we should bundle everything into one argument instead of creating two separate signatures. I've opened a PR that targets your PR branch. That catches your PR up to |
This PR improves (at least IMO) the usage for the service server.
First of all a create_service now only takes one generic argument, which is the service type. So this
becomes this
which I think is much cleaner.
Then I removed the request_header from the service callback, as almost nobody is using it. People who still want it can use the
create_service_with_header
method.And lastly I made the callbacks FnMut, which makes services like this work: