From bda6fe673e17979f6cfe7177607a363913bbaff3 Mon Sep 17 00:00:00 2001 From: Jali Date: Sun, 28 Jun 2020 23:39:17 +0200 Subject: [PATCH] Added base for Request future --- .idea/workspace.xml | 29 +++++++++++++---------------- src/gopher.rs | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fdadf19..3fdde61 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -23,12 +23,8 @@ - - - - - + + @@ -160,26 +157,26 @@ - + - - + + - - + + - - + + - - + + - + diff --git a/src/gopher.rs b/src/gopher.rs index 9356f98..ec0d1fb 100644 --- a/src/gopher.rs +++ b/src/gopher.rs @@ -4,8 +4,32 @@ //! Version: 1.0.20166.1 //! Created By: Jali +use std::future::Future; +use std::io; +use std::pin::Pin; use tokio::net::TcpStream; -use tokio::io; +use tokio::prelude::{AsyncRead, AsyncWrite}; + +/** + * # Description + * + * A future that asynchronously reads requests from the reader and copies the + * contents of a file back to the writer. + * + * This struct is generally created by calling [`request`][request]. Please + * the the documentation of `request()` for more details. + */ +#[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] +pub struct Request<'a, R: ?Sized, W: ?Sized> { + reader: &'a mut R, + read_done: bool, + writer: &'a mut W, + pos: usize, + cap: usize, + amt: u64, + buf: Box<[u8]> +} /** * # Description @@ -24,6 +48,18 @@ use tokio::io; * let amount = gopher::request(reader, writer); * ``` **/ -pub fn request(reader: io::ReadHalf, writer: io::WriteHalf) -> int32 { - +pub fn request<'a, R, W>(reader: &'a mut R, writer: &'a mut W) -> Request<'a, R, W> +where + R: AsyncRead + Unpin + ?Sized, + W: AsyncWrite + Unpin + ?Sized +{ + Request { + reader, + read_done: false, + writer, + amt: 0, + pos: 0, + cap: 0, + buf: Box::new(*[0; 2048]), + } } \ No newline at end of file