From 4823c55e8ba1d37ee4216fae4f9a19cf8e59808d Mon Sep 17 00:00:00 2001 From: Hubert Date: Tue, 13 Jul 2021 08:21:30 +0200 Subject: [PATCH] save --- src/tostream.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tostream.rs b/src/tostream.rs index 2d52c3f..34b0830 100644 --- a/src/tostream.rs +++ b/src/tostream.rs @@ -6,11 +6,20 @@ use std::io::Error; struct ToStream(T); +impl ToStream { + fn get_field(self: Pin<&mut Self>) -> Pin<&mut T> { + unsafe { self.map_unchecked_mut(|s| &mut s.0) } + } +} + +impl Unpin for ToStream{} + impl Stream for ToStream{ type Item = Result; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { 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)) } } \ No newline at end of file