use std::fmt;
use std::pin::Pin;
use crate::io::{self, Read};
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 Read 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()))
}
}