This commit is contained in:
Hubert 2021-07-13 08:21:30 +02:00
parent 5464c78e37
commit 4823c55e8b
1 changed files with 10 additions and 1 deletions

View File

@ -6,11 +6,20 @@ use std::io::Error;
struct ToStream<T>(T);
impl<T> ToStream<T> {
fn get_field(self: Pin<&mut Self>) -> Pin<&mut T> {
unsafe { self.map_unchecked_mut(|s| &mut s.0) }
}
}
impl <T : Unpin> Unpin for ToStream<T>{}
impl <T : AsyncRead> Stream for ToStream<T>{
type Item = Result<Bytes, Error>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let mut buff: [u8; 1024] = [0; 1024];
self.0.poll_read(cx, &mut buff[..]).map_ok(|l| {Bytes::copy_from_slice(&buff[0..l])}) // il manque Option
let mut t = self.get_field();
t.poll_read(cx, &mut buff[..]).map_ok(|l| {Bytes::copy_from_slice(&buff[0..l])}).map(|res| Some(res))
}
}