Aliasing in trait bounds

Hello - noob here

See the constraint/bounds for S, could that not be aliased to be something like ActixService<B>?

As a learner of Rust, it seems like this stuff could be condensed and made less cognitively demanding. The intention of this question is about:

  • whether it is possible
  • whether it is but the Actix devs just didn't (yet)
  • whether it's not possible, and
  • whether it should be made possible in future Rust
// Middleware factory is `Transform` trait
// `S` - type of the next service
// `B` - type of response's body
impl<S, B> Transform<S, ServiceRequest> for SayHi
where
    S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
    S::Future: 'static,
    B: 'static,
{
    type Response = ServiceResponse<B>;
    type Error = Error;
    type InitError = ();
    type Transform = SayHiMiddleware<S>;
    type Future = Ready<Result<Self::Transform, Self::InitError>>;

    fn new_transform(&self, service: S) -> Self::Future {
        ready(Ok(SayHiMiddleware { service }))
    }
}

I believe you're wishing that trait aliases were stable.

You can sometimes use subtraits to accomplish something similar.

// Back of napkin, unchecked example
trait SubTransform<S, B>
where
    Self: Transform<
        S: Service<ServiceRequest, Response = ServiceResponse<B>>
    >,
    Self: Transform<
        S: Service<
            ServiceRequest,
            Error = Error,
            Future: 'static,
            Response: 'static
        >,
    >,
{}
impl<T, S, B> SubTransform<S, B> for T
where
   T: /* ... the same bounds */
{}

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.