I have a struct with two members each of which is a pretty complicated type. If I were to write out the types in full it would look something like the following which isn't valid since _
can not be used in this context:
pub struct Device {
pub requests: Framed<FramedWrite<WriteHalf<TcpStream>, LengthDelimitedCodec>, Request, _, _>,
pub responses: Framed<FramedRead<ReadHalf<TcpStream>, LengthDelimitedCodec>, Response, _, _>
}
So I thought I could solve this problem by just specifying the trait bounds that I care about on these members, for example:
pub struct Device<Tx, Rx>
where Tx: futures::Sink<protocol::Request>,
Rx: futures::Stream<Item = protocol::Response> {
pub requests: Tx,
pub responses: Rx,
}
However, this isn't ideal since the struct is now generic over Rx
and Tx
with respect to the specified bounds which is not the functionality that I wanted and now forces me to specify these types a level up.
Is there a way of defining my struct without writing out the full type signatures but at the same time not being generic over Rx
and Tx
?