Skip to content

RpcServiceT: remove associated type Future and replace with impl future #1289

Closed
@niklasad1

Description

@niklasad1

Currently the RpcServiceT is very similar to the tower::Service

pub trait RpcServiceT<'a> {
	/// The future response value.
	type Future: Future<Output = MethodResponse> + Send;

	/// Process a single JSON-RPC call it may be a subscription or regular call.
	/// In this interface they are treated in the same way but it's possible to
	/// distinguish those based on the `MethodResponse`.
	fn call(&self, request: Request<'a>) -> Self::Future;

and it should be modified to

pub trait RpcServiceT<'a> {
	/// Process a single JSON-RPC call it may be a subscription or regular call.
	/// In this interface they are treated in the same way but it's possible to
	/// distinguish those based on the `MethodResponse`.
	fn call(&self, request: Request<'a>) -> impl Future<Output = MethodResponse> + Send;
}

The reason is that in many cases the current design ends up with that the Future needs to be Boxed
or a complicated ResponseFuture has to be written. With impl Future is much more flexible and would improve things.

The only reason why we haven't changed this is because changing this ends up with rustc generic lifetime error, rust-lang/rust#100013

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions