use tokio::io::AsyncWriteExt;
#[inline]
#[allow(clippy::uninit_vec)]
pub fn allocate_vec<T>(len: usize) -> Vec<T> {
let mut ret = Vec::with_capacity(len);
unsafe {
ret.set_len(len);
}
ret
}
// a cancellable alternative to AsyncWriteExt::write_all
pub async fn write_all<T: AsyncWriteExt + Unpin>(
stream: &mut T,
buf: &[u8],
) -> std::io::Result<()> {
let mut i = 0;
let n = buf.len();
while i < n {
let n = stream.write(&buf[i..]).await?;
i += n;
}
Ok(())
}