k8_client/client/
log_stream.rs1use std::{pin::Pin, task::Poll};
2
3use bytes::{Bytes, BufMut};
4use futures_util::{AsyncRead, Stream, StreamExt};
5
6pub struct LogStream(pub Pin<Box<dyn Stream<Item = Bytes> + Send + Sync + 'static>>);
7
8impl AsyncRead for LogStream {
9 fn poll_read(
10 mut self: Pin<&mut Self>,
11 cx: &mut std::task::Context<'_>,
12 mut buf: &mut [u8],
13 ) -> std::task::Poll<std::io::Result<usize>> {
14 match self.0.poll_next_unpin(cx) {
15 Poll::Ready(Some(chunk)) => {
16 buf.put_slice(&chunk);
17 buf.put_u8(0x0A);
18 Poll::Ready(std::io::Result::Ok(chunk.len() + 1))
19 }
20 Poll::Ready(None) => Poll::Ready(std::io::Result::Ok(0)),
21 Poll::Pending => Poll::Pending,
22 }
23 }
24}