Reduce the number of dependencies

This commit is contained in:
Stjepan Glavina 2020-07-20 00:55:35 +02:00
parent 80461663c4
commit 7a73c22814
18 changed files with 42 additions and 35 deletions

View File

@ -46,7 +46,8 @@ async-std = "1.5.0"
async-tungstenite = { version = "0.4.2", features = ["async-native-tls"] }
base64 = "0.12.0"
ctrlc = "3.1.4"
futures = "0.3.4"
futures = "0.3.5"
futures-lite = { path = "../futures-lite" }
http = "0.2.1"
http-types = "1.2.0"
hyper = { version = "0.13.5", default-features = false, features = ["stream"] }

View File

@ -11,7 +11,7 @@ use std::net::{TcpStream, ToSocketAddrs};
use anyhow::{bail, Context as _, Error, Result};
use async_io::Async;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures_lite::*;
use http_types::{Method, Request, Response};
use url::Url;

View File

@ -19,7 +19,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor};
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
use http_types::{Request, Response, StatusCode};
use smol::Task;

View File

@ -16,8 +16,7 @@ use std::net::TcpStream;
use async_io::Async;
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
fn main() -> io::Result<()> {
block_on(async {
@ -35,10 +34,19 @@ fn main() -> io::Result<()> {
let mut writer = &stream;
// Wait until the standard input is closed or the connection is closed.
futures::select! {
_ = io::copy(stdin, &mut writer).fuse() => println!("Quit!"),
_ = io::copy(reader, &mut stdout).fuse() => println!("Server disconnected!"),
}
future::race(
async {
let res = io::copy(stdin, &mut writer).await;
println!("Quit!");
res
},
async {
let res = io::copy(reader, &mut stdout).await;
println!("Server disconnected!");
res
},
)
.await?;
Ok(())
})

View File

@ -19,8 +19,7 @@ use async_channel::{bounded, Receiver, Sender};
use async_dup::Arc;
use async_io::Async;
use blocking::block_on;
use futures::io::{self, BufReader};
use futures::prelude::*;
use futures_lite::*;
use smol::Task;
/// An event on the chat server.
@ -70,7 +69,7 @@ async fn dispatch(receiver: Receiver<Event>) -> io::Result<()> {
/// Reads messages from the client and forwards them to the dispatcher task.
async fn read_messages(sender: Sender<Event>, client: Arc<Async<TcpStream>>) -> io::Result<()> {
let addr = client.get_ref().peer_addr()?;
let mut lines = BufReader::new(client).lines();
let mut lines = io::BufReader::new(client).lines();
while let Some(line) = lines.next().await {
let line = line?;

View File

@ -7,13 +7,13 @@
//! ```
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
fn main() {
// Set a handler that sends a message through a channel.
let (s, ctrl_c) = async_channel::bounded(100);
let handle = move || {
let _ = s.send(()).now_or_never();
let _ = future::poll_once(s.send(()));
};
ctrlc::set_handler(handle).unwrap();

View File

@ -16,7 +16,7 @@ use anyhow::{bail, Context as _, Error, Result};
use async_io::Async;
use async_native_tls::TlsStream;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures_lite::*;
use http::Uri;
use hyper::{Body, Client, Request, Response};
use smol::Task;
@ -42,7 +42,7 @@ fn main() -> Result<()> {
// Read the message body.
let body = resp
.into_body()
.try_fold(Vec::new(), |mut body, chunk| async move {
.try_fold(Vec::new(), |mut body, chunk| {
body.extend_from_slice(&chunk);
Ok(body)
})
@ -70,7 +70,7 @@ struct SmolConnector;
impl hyper::service::Service<Uri> for SmolConnector {
type Response = SmolStream;
type Error = Error;
type Future = future::BoxFuture<'static, Result<Self::Response, Self::Error>>;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))

View File

@ -23,7 +23,7 @@ use anyhow::{Error, Result};
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use smol::Task;
@ -103,7 +103,7 @@ impl hyper::server::accept::Accept for SmolListener {
cx: &mut Context,
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
let poll = Pin::new(&mut self.listener.incoming()).poll_next(cx);
let stream = futures::ready!(poll).unwrap()?;
let stream = ready!(poll).unwrap()?;
let stream = match &self.tls {
None => SmolStream::Plain(stream),
@ -132,7 +132,7 @@ enum SmolStream {
Tls(TlsStream<Async<TcpStream>>),
/// A TCP connection that is in process of getting secured by TLS.
Handshake(future::BoxFuture<'static, io::Result<TlsStream<Async<TcpStream>>>>),
Handshake(Pin<Box<dyn Future<Output = io::Result<TlsStream<Async<TcpStream>>>> + Send>>),
}
impl hyper::client::connect::Connection for SmolStream {
@ -152,7 +152,7 @@ impl tokio::io::AsyncRead for SmolStream {
SmolStream::Plain(s) => return Pin::new(s).poll_read(cx, buf),
SmolStream::Tls(s) => return Pin::new(s).poll_read(cx, buf),
SmolStream::Handshake(f) => {
let s = futures::ready!(f.as_mut().poll(cx))?;
let s = ready!(f.as_mut().poll(cx))?;
*self = SmolStream::Tls(s);
}
}
@ -171,7 +171,7 @@ impl tokio::io::AsyncWrite for SmolStream {
SmolStream::Plain(s) => return Pin::new(s).poll_write(cx, buf),
SmolStream::Tls(s) => return Pin::new(s).poll_write(cx, buf),
SmolStream::Handshake(f) => {
let s = futures::ready!(f.as_mut().poll(cx))?;
let s = ready!(f.as_mut().poll(cx))?;
*self = SmolStream::Tls(s);
}
}

View File

@ -11,7 +11,7 @@ use std::net::{TcpStream, ToSocketAddrs};
use anyhow::{bail, Context as _, Result};
use async_io::Async;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures_lite::*;
use url::Url;
/// Sends a GET request and fetches the response.

View File

@ -19,7 +19,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor};
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
use smol::Task;
const RESPONSE: &[u8] = br#"

View File

@ -16,8 +16,7 @@ use std::net::TcpStream;
use async_io::Async;
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
fn main() -> io::Result<()> {
block_on(async {

View File

@ -16,7 +16,7 @@ use std::net::{TcpListener, TcpStream};
use async_io::Async;
use blocking::block_on;
use futures::io;
use futures_lite::*;
use smol::Task;
/// Echoes messages from the client back to it.

View File

@ -18,8 +18,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Certificate, TlsConnector};
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
fn main() -> Result<()> {
// Initialize TLS with the local certificate.

View File

@ -18,7 +18,7 @@ use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use blocking::block_on;
use futures::io;
use futures_lite::*;
use smol::Task;
/// Echoes messages from the client back to it.

View File

@ -12,7 +12,7 @@ fn main() -> std::io::Result<()> {
use async_io::Async;
use blocking::block_on;
use futures::prelude::*;
use futures_lite::*;
block_on(async {
// Create a Unix stream that receives a byte on each signal occurrence.

View File

@ -21,7 +21,8 @@ use async_io::Async;
use async_native_tls::{Certificate, TlsConnector, TlsStream};
use async_tungstenite::WebSocketStream;
use blocking::{block_on, unblock};
use futures::prelude::*;
use futures::sink::{Sink, SinkExt};
use futures_lite::*;
use tungstenite::handshake::client::Response;
use tungstenite::Message;
use url::Url;

View File

@ -21,7 +21,8 @@ use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use async_tungstenite::WebSocketStream;
use blocking::block_on;
use futures::prelude::*;
use futures::sink::{Sink, SinkExt};
use futures_lite::*;
use smol::Task;
use tungstenite::Message;

View File

@ -12,8 +12,7 @@ fn main() -> std::io::Result<()> {
use async_io::Async;
use blocking::{block_on, Unblock};
use futures::io;
use futures::prelude::*;
use futures_lite::*;
use smol::Task;
use tempfile::tempdir;
use uds_windows::{UnixListener, UnixStream};