Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
@@ -0,0 +1,52 @@
use core::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
use futures::ready;
use tokio::io::{AsyncBufRead, AsyncWrite};
pub fn copy_buf<R, W>(reader: R, writer: &mut W) -> CopyBuf<'_, R, W>
where
R: AsyncBufRead + Unpin,
W: AsyncWrite + Unpin + ?Sized,
{
CopyBuf {
reader,
writer,
amt: 0,
}
}
#[derive(Debug)]
pub struct CopyBuf<'a, R, W: ?Sized> {
reader: R,
writer: &'a mut W,
amt: u64,
}
impl<R, W> Future for CopyBuf<'_, R, W>
where
R: AsyncBufRead + Unpin,
W: AsyncWrite + Unpin + ?Sized,
{
type Output = std::io::Result<u64>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = &mut *self;
loop {
let buffer = ready!(Pin::new(&mut this.reader).poll_fill_buf(cx))?;
if buffer.is_empty() {
ready!(Pin::new(&mut this.writer).poll_flush(cx))?;
return Poll::Ready(Ok(this.amt));
}
let i = ready!(Pin::new(&mut this.writer).poll_write(cx, buffer))?;
if i == 0 {
return Poll::Ready(Err(std::io::ErrorKind::WriteZero.into()));
}
this.amt += i as u64;
Pin::new(&mut this.reader).consume(i);
}
}
}
@@ -0,0 +1,66 @@
use std::{
pin::Pin,
task::{Context, Poll},
};
pub struct InterleavePending<T> {
inner: T,
pended: bool,
}
impl<T> InterleavePending<T> {
pub(crate) fn new(inner: T) -> Self {
Self {
inner,
pended: false,
}
}
}
impl<W: tokio::io::AsyncWrite + Unpin> tokio::io::AsyncWrite for InterleavePending<W> {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<std::io::Result<usize>> {
if self.pended {
let next = Pin::new(&mut self.inner).poll_write(cx, buf);
if next.is_ready() {
self.pended = false;
}
next
} else {
cx.waker().wake_by_ref();
self.pended = true;
Poll::Pending
}
}
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
if self.pended {
let next = Pin::new(&mut self.inner).poll_flush(cx);
if next.is_ready() {
self.pended = false;
}
next
} else {
cx.waker().wake_by_ref();
self.pended = true;
Poll::Pending
}
}
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
if self.pended {
let next = Pin::new(&mut self.inner).poll_shutdown(cx);
if next.is_ready() {
self.pended = false;
}
next
} else {
cx.waker().wake_by_ref();
self.pended = true;
Poll::Pending
}
}
}
@@ -0,0 +1,35 @@
use std::{
pin::Pin,
task::{Context, Poll},
};
#[derive(Debug)]
pub struct Limited<Io> {
io: Io,
limit: usize,
}
impl<Io> Limited<Io> {
pub(crate) fn new(io: Io, limit: usize) -> Limited<Io> {
Limited { io, limit }
}
}
impl<W: tokio::io::AsyncWrite + Unpin> tokio::io::AsyncWrite for Limited<W> {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<std::io::Result<usize>> {
let limit = self.limit;
Pin::new(&mut self.io).poll_write(cx, &buf[..std::cmp::min(limit, buf.len())])
}
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.io).poll_flush(cx)
}
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.io).poll_shutdown(cx)
}
}
@@ -0,0 +1,23 @@
mod copy_buf;
mod interleave_pending;
mod limited;
pub use copy_buf::copy_buf;
pub trait AsyncWriteTestExt: tokio::io::AsyncWrite {
fn interleave_pending_write(self) -> interleave_pending::InterleavePending<Self>
where
Self: Sized + Unpin,
{
interleave_pending::InterleavePending::new(self)
}
fn limited_write(self, limit: usize) -> limited::Limited<Self>
where
Self: Sized + Unpin,
{
limited::Limited::new(self, limit)
}
}
impl<T: tokio::io::AsyncWrite> AsyncWriteTestExt for T {}