multistream-select: Less allocations. (#800)

This commit is contained in:
Toralf Wittner
2019-01-09 15:09:35 +01:00
committed by GitHub
parent aedf9c0c31
commit f1959252b7
9 changed files with 467 additions and 372 deletions

View File

@ -22,15 +22,13 @@
#![cfg(test)]
use crate::ProtocolChoiceError;
use crate::dialer_select::{dialer_select_proto_parallel, dialer_select_proto_serial};
use crate::protocol::{Dialer, DialerToListenerMessage, Listener, ListenerToDialerMessage};
use crate::{dialer_select_proto, listener_select_proto};
use futures::prelude::*;
use tokio::runtime::current_thread::Runtime;
use tokio_tcp::{TcpListener, TcpStream};
use bytes::Bytes;
use crate::dialer_select::{dialer_select_proto_parallel, dialer_select_proto_serial};
use futures::Future;
use futures::{Sink, Stream};
use crate::protocol::{Dialer, DialerToListenerMessage, Listener, ListenerToDialerMessage};
use crate::ProtocolChoiceError;
use crate::{dialer_select_proto, listener_select_proto};
/// Holds a `Vec` and satifies the iterator requirements of `listener_select_proto`.
struct VecRefIntoIter<T>(Vec<T>);
@ -68,7 +66,7 @@ fn negotiate_with_self_succeeds() {
.from_err()
.and_then(move |stream| Dialer::new(stream))
.and_then(move |dialer| {
let p = Bytes::from("/hello/1.0.0");
let p = b"/hello/1.0.0";
dialer.send(DialerToListenerMessage::ProtocolRequest { name: p })
})
.and_then(move |dialer| dialer.into_future().map_err(|(e, _)| e))