Question: generic trait in crate actix_http

Service implementation have no generic <Req> on Service type, and I assumed actix code compiles fine, but Trait Service do encompass generic <Req> over Service.

I created a small snippet to test generic trait

use std::fmt::Display;
use std::iter::Iterator;
pub struct InnerConnectorResponseB<T>
where
    T: Iterator,
{
    field: T,
}

pub trait Service<Req> {
    type Response;

    fn call(&self, req: Req);
}

/// <S> Removal introduce a compiler error
impl<T, S> Service<S> for InnerConnectorResponseB<T>
where
    T: Iterator,
    S: Display,
{
    type Response = T;
    fn call(&self, req: S) {}
}

Without <S> over Service, compiler won't able distinguish types over Service. But it's still kind of make sense for me to elide <S> as the S in call(&self, req: S) is the only limitation to constrain the Service(Meaning If S is any concrete type X. Base on template of trait, Service have to be that X) , ambiguities are lifted!

How actix_http crate make this working but not for the sample code ?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.