Function multistream_select::dialer_select_proto
source · pub fn dialer_select_proto<R, I>(
inner: R,
protocols: I
) -> DialerSelectFuture<R, I::IntoIter>where
R: AsyncRead + AsyncWrite,
I: IntoIterator,
I::Item: AsRef<[u8]>,
Expand description
Helps selecting a protocol amongst the ones supported.
This function expects a socket and a list of protocols. It uses the multistream-select
protocol to choose with the remote a protocol amongst the ones produced by the iterator.
The iterator must produce a tuple of a protocol name advertised to the remote, a function that
checks whether a protocol name matches the protocol, and a protocol “identifier” of type P
(you decide what P
is). The parameters of the match function are the name proposed by the
remote, and the protocol name that we passed (so that you don’t have to clone the name). On
success, the function returns the identifier (of type P
), plus the socket which now uses that
chosen protocol.