Skip to content

Instantly share code, notes, and snippets.

@yoshuawuyts
Created July 28, 2019 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshuawuyts/846b929c7938fd545bcbacbdfbdd4c55 to your computer and use it in GitHub Desktop.
Save yoshuawuyts/846b929c7938fd545bcbacbdfbdd4c55 to your computer and use it in GitHub Desktop.
trait AsyncRead {
async fn read(&self, buf: &mut [u8]) -> io::Result<usize>;
}
fn main () {
let mut buf = vec![0; 1024];
let bytes_read = read(&mut buf).await?;
dbg!(buf);
}
////
trait AsyncRead {
fn read(&self, buf: Vec<u8>) -> Future<Output = (io::Result<usize>>, Vec<u8>);
}
fn main () {
let mut buf = vec![0; 1024];
let (bytes_read, buf) = read(buf).await?;
dbg!(buf);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment