use std::fmt;
use std::pin::Pin;
use futures_io::{AsyncRead, Initializer};
use crate::io;
use crate::task::{Context, Poll};
pub fn repeat(byte: u8) -> Repeat {
Repeat { byte }
}
pub struct Repeat {
byte: u8,
}
impl fmt::Debug for Repeat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Empty { .. }")
}
}
impl AsyncRead for Repeat {
#[inline]
fn poll_read(
self: Pin<&mut Self>,
_: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
for b in &mut *buf {
*b = self.byte;
}
Poll::Ready(Ok(buf.len()))
}
#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
}
}