'Is there a cleaner way for passing a bunch of generics?

I have this function with two generic parameters and I will have to add more of them.

Is there a cleaner way to do this?

fn handle_connection<Reqparser: traits::Reqparser<Stream = Stream>, Responder: traits::Responder>(mut stream: Stream) {...}


Solution 1:[1]

You can use a where clause when an inline generic parameter list gets unwieldy:

fn handle_connection<Reqparser, Responder>(mut stream: Stream)
where
    Reqparser: traits::Reqparser<Stream = Stream>,
    Responder: traits::Responder,
{
    ...
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Kugelman