From 31ec42bf3a6ac3be78651a9a68565b8dac526ec0 Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Mon, 9 Mar 2020 00:18:50 -0400 Subject: [PATCH] generics!! --- hptp-recv/src/main.rs | 8 ++++++-- hptp-send/src/main.rs | 16 +++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hptp-recv/src/main.rs b/hptp-recv/src/main.rs index 5d2913d..e0265ec 100644 --- a/hptp-recv/src/main.rs +++ b/hptp-recv/src/main.rs @@ -5,7 +5,7 @@ extern crate tokio; extern crate thiserror; use hptp::log::Logger; -use tokio::io::{AsyncWriteExt, Stdout}; +use tokio::io::AsyncWrite; use tokio::net::UdpSocket; #[derive(Error, Debug)] @@ -44,7 +44,11 @@ async fn start(log: &mut Logger) -> Result<(), Error> { download(log, sock, tokio::io::stdout()).await } -async fn download(log: &mut Logger, mut sock: UdpSocket, mut out: Stdout) -> Result<(), Error> { +async fn download(log: &mut Logger, mut sock: UdpSocket, mut out: OUT) -> Result<(), Error> +where + OUT: AsyncWrite + Unpin, +{ + use tokio::io::AsyncWriteExt; let mut buf = [0u8; 2000]; let mut pos = 0; loop { diff --git a/hptp-send/src/main.rs b/hptp-send/src/main.rs index 90f486a..55192bc 100644 --- a/hptp-send/src/main.rs +++ b/hptp-send/src/main.rs @@ -6,7 +6,7 @@ extern crate thiserror; use hptp::log::Logger; use std::net::SocketAddrV4; -use tokio::io::{AsyncReadExt, Stdin}; +use tokio::io::AsyncRead; use tokio::net::UdpSocket; #[derive(Error, Debug)] @@ -54,9 +54,7 @@ async fn start(log: &mut Logger) -> Result<(), Error> { .map_err(|_| Error::NoAvailPort)?; log.debug_msg(format!("bound on {}", sock.local_addr()?)) .await; - upload(log, sock, tokio::io::stdin(), targ_addr).await?; - log.debug_msg("bye!").await; - Ok(()) + upload(log, sock, tokio::io::stdin(), targ_addr).await } fn parse_args(mut args: impl Iterator) -> Result { @@ -66,12 +64,16 @@ fn parse_args(mut args: impl Iterator) -> Result( log: &mut Logger, mut sock: UdpSocket, - mut inp: Stdin, + mut inp: IN, targ_addr: SocketAddrV4, -) -> Result<(), Error> { +) -> Result<(), Error> +where + IN: AsyncRead + Unpin, +{ + use tokio::io::AsyncReadExt; let mut buf = [0u8; 500]; let mut pos = 0; loop {