Skip to content

Consider impl <T, R: Into<T>> IntoRequest<T> for R #2463

@stevenroose

Description

@stevenroose

Feature Request

Tonic's client functions take IntoRequest<T> for the request type. But if I have a type R that implements Into<T>, I can't pass my_r.into() into the function because the type system won't figure out that I want the .into() for T.

If we'd have a generic implementation as below, we could pass an R object into the client method.

impl <R, T: From<R>> IntoRequest<T> for R {
    fn into_request(self) -> Request<T> {
        T::from(self).into_request()
    }
}

Motivation

Simplifying calling client functions with custom structs that Into the protobuf requests. I think this is a common pattern. The protobuf messages use only the raw types, so often clients have structs with business logic types and then conversion Into and TryFrom implementations between business-logic structs and protobuf structs.

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