Vendor asic-rs 0.8.1 (280 crates, offline builds) + wxWidgets 3.3.3 (pristine + patch queue); UI spec + ADR-0003; M1 on asic-rs
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
use crate::{
|
||||
codecs::DecodeV2,
|
||||
core::util::{PartialBuffer, WriteBuffer},
|
||||
generic::bufread::impl_decoder,
|
||||
};
|
||||
|
||||
use std::{
|
||||
io::{IoSlice, Result},
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
|
||||
|
||||
impl_decoder!();
|
||||
|
||||
impl<R: AsyncBufRead, D: DecodeV2> AsyncRead for Decoder<R, D> {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut ReadBuf<'_>,
|
||||
) -> Poll<Result<()>> {
|
||||
super::poll_read(buf, |output| self.do_poll_read(cx, output))
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: AsyncWrite, D> AsyncWrite for Decoder<R, D> {
|
||||
fn poll_write(
|
||||
mut self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize>> {
|
||||
self.get_pin_mut().poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_write_vectored(
|
||||
mut self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
mut bufs: &[IoSlice<'_>],
|
||||
) -> Poll<Result<usize>> {
|
||||
self.get_pin_mut().poll_write_vectored(cx, bufs)
|
||||
}
|
||||
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
self.get_ref().is_write_vectored()
|
||||
}
|
||||
|
||||
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
self.get_pin_mut().poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
self.get_pin_mut().poll_shutdown(cx)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
use crate::{
|
||||
codecs::EncodeV2,
|
||||
core::util::{PartialBuffer, WriteBuffer},
|
||||
generic::bufread::impl_encoder,
|
||||
};
|
||||
use std::{
|
||||
io::{IoSlice, Result},
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
|
||||
|
||||
impl_encoder!();
|
||||
|
||||
impl<R: AsyncBufRead, E: EncodeV2> AsyncRead for Encoder<R, E> {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut ReadBuf<'_>,
|
||||
) -> Poll<Result<()>> {
|
||||
super::poll_read(buf, |output| self.do_poll_read(cx, output))
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: AsyncWrite, E> AsyncWrite for Encoder<R, E> {
|
||||
fn poll_write(
|
||||
mut self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> Poll<Result<usize>> {
|
||||
self.get_pin_mut().poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_write_vectored(
|
||||
mut self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
mut bufs: &[IoSlice<'_>],
|
||||
) -> Poll<Result<usize>> {
|
||||
self.get_pin_mut().poll_write_vectored(cx, bufs)
|
||||
}
|
||||
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
self.get_ref().is_write_vectored()
|
||||
}
|
||||
|
||||
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
self.get_pin_mut().poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
|
||||
self.get_pin_mut().poll_shutdown(cx)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
mod decoder;
|
||||
mod encoder;
|
||||
|
||||
pub use self::{decoder::Decoder, encoder::Encoder};
|
||||
|
||||
use crate::core::util::WriteBuffer;
|
||||
use std::{io::Result, task::Poll};
|
||||
use tokio::io::ReadBuf;
|
||||
|
||||
fn poll_read(
|
||||
buf: &mut ReadBuf<'_>,
|
||||
do_poll_read: impl FnOnce(&mut WriteBuffer<'_>) -> Poll<Result<()>>,
|
||||
) -> Poll<Result<()>> {
|
||||
if buf.remaining() == 0 {
|
||||
return Poll::Ready(Ok(()));
|
||||
}
|
||||
|
||||
let initialized = buf.initialized().len() - buf.filled().len();
|
||||
// Safety: `WriteBuffer` has the same safety invariant as `ReadBuf`
|
||||
let mut output = WriteBuffer::new_uninitialized(unsafe { buf.unfilled_mut() });
|
||||
// Safety: `ReadBuf` ensures that it is initialized
|
||||
unsafe { output.assume_init(initialized) };
|
||||
|
||||
let res = do_poll_read(&mut output);
|
||||
|
||||
let initialized = output.initialized_len();
|
||||
let written = output.written_len();
|
||||
|
||||
// Safety: We trust our implementation to have properly initialized it
|
||||
unsafe { buf.assume_init(initialized) };
|
||||
buf.advance(written);
|
||||
|
||||
res
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
macro_rules! decoder {
|
||||
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
|
||||
pin_project_lite::pin_project! {
|
||||
$(#[$attr])*
|
||||
///
|
||||
/// This structure implements an [`AsyncRead`](tokio::io::AsyncRead) interface and will
|
||||
/// read compressed data from an underlying stream and emit a stream of uncompressed data.
|
||||
#[derive(Debug)]
|
||||
pub struct $name<$inner> {
|
||||
#[pin]
|
||||
inner: crate::tokio::bufread::Decoder<$inner, crate::codecs::$name>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncBufRead> $name<$inner> {
|
||||
/// Creates a new decoder which will read compressed data from the given stream and
|
||||
/// emit an uncompressed stream.
|
||||
pub fn new(read: $inner) -> $name<$inner> {
|
||||
$name {
|
||||
inner: crate::tokio::bufread::Decoder::new(read, crate::codecs::$name::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new decoder with the given codec, which will read compressed data from the given stream and
|
||||
/// emit an uncompressed stream.
|
||||
pub fn with_codec(read: $inner, codec: crate::codecs::$name) -> $name<$inner> {
|
||||
$name {
|
||||
inner: crate::tokio::bufread::Decoder::new(read, codec)
|
||||
}
|
||||
}
|
||||
|
||||
$($($inherent_methods)*)*
|
||||
}
|
||||
|
||||
impl<$inner> $name<$inner> {
|
||||
/// Configure multi-member/frame decoding, if enabled this will reset the decoder state
|
||||
/// when reaching the end of a compressed member/frame and expect either EOF or another
|
||||
/// compressed member/frame to follow it in the stream.
|
||||
pub fn multiple_members(&mut self, enabled: bool) {
|
||||
self.inner.multiple_members(enabled);
|
||||
}
|
||||
|
||||
/// Acquires a reference to the underlying reader that this decoder is wrapping.
|
||||
pub fn get_ref(&self) -> &$inner {
|
||||
self.inner.get_ref()
|
||||
}
|
||||
|
||||
/// Acquires a mutable reference to the underlying reader that this decoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the reader which
|
||||
/// may otherwise confuse this decoder.
|
||||
pub fn get_mut(&mut self) -> &mut $inner {
|
||||
self.inner.get_mut()
|
||||
}
|
||||
|
||||
/// Acquires a pinned mutable reference to the underlying reader that this decoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the reader which
|
||||
/// may otherwise confuse this decoder.
|
||||
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
|
||||
self.project().inner.get_pin_mut()
|
||||
}
|
||||
|
||||
/// Consumes this decoder returning the underlying reader.
|
||||
///
|
||||
/// Note that this may discard internal state of this decoder, so care should be taken
|
||||
/// to avoid losing resources when this is called.
|
||||
pub fn into_inner(self) -> $inner {
|
||||
self.inner.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncBufRead> tokio::io::AsyncRead for $name<$inner> {
|
||||
fn poll_read(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.project().inner.poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncWrite> tokio::io::AsyncWrite for $name<$inner> {
|
||||
fn poll_write(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> std::task::Poll<std::io::Result<usize>> {
|
||||
self.get_pin_mut().poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.get_pin_mut().poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.get_pin_mut().poll_shutdown(cx)
|
||||
}
|
||||
|
||||
fn poll_write_vectored(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
bufs: &[std::io::IoSlice<'_>],
|
||||
) -> std::task::Poll<std::io::Result<usize>> {
|
||||
self.get_pin_mut().poll_write_vectored(cx, bufs)
|
||||
}
|
||||
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
self.get_ref().is_write_vectored()
|
||||
}
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
use crate::core::util::{_assert_send, _assert_sync};
|
||||
use core::pin::Pin;
|
||||
use tokio::io::AsyncBufRead;
|
||||
|
||||
_assert_send::<$name<Pin<Box<dyn AsyncBufRead + Send>>>>();
|
||||
_assert_sync::<$name<Pin<Box<dyn AsyncBufRead + Sync>>>>();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
macro_rules! encoder {
|
||||
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
|
||||
pin_project_lite::pin_project! {
|
||||
$(#[$attr])*
|
||||
///
|
||||
/// This structure implements an [`AsyncRead`](tokio::io::AsyncRead) interface and will
|
||||
/// read uncompressed data from an underlying stream and emit a stream of compressed data.
|
||||
#[derive(Debug)]
|
||||
pub struct $name<$inner> {
|
||||
#[pin]
|
||||
inner: crate::tokio::bufread::Encoder<$inner, crate::codecs::$name>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncBufRead> $name<$inner> {
|
||||
$(
|
||||
/// Creates a new encoder which will read uncompressed data from the given stream
|
||||
/// and emit an compressed stream.
|
||||
///
|
||||
$($inherent_methods)*
|
||||
)*
|
||||
|
||||
/// Creates a new encoder with the given codec, which will read uncompressed data from the given stream
|
||||
/// and emit an compressed stream.
|
||||
pub fn with_codec(read: $inner, codec: crate::codecs::$name) -> $name<$inner> {
|
||||
$name {
|
||||
inner: crate::tokio::bufread::Encoder::new(read, codec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner> $name<$inner> {
|
||||
/// Acquires a reference to the underlying reader that this encoder is wrapping.
|
||||
pub fn get_ref(&self) -> &$inner {
|
||||
self.inner.get_ref()
|
||||
}
|
||||
|
||||
/// Acquires a mutable reference to the underlying reader that this encoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the reader which
|
||||
/// may otherwise confuse this encoder.
|
||||
pub fn get_mut(&mut self) -> &mut $inner {
|
||||
self.inner.get_mut()
|
||||
}
|
||||
|
||||
/// Acquires a pinned mutable reference to the underlying reader that this encoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the reader which
|
||||
/// may otherwise confuse this encoder.
|
||||
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
|
||||
self.project().inner.get_pin_mut()
|
||||
}
|
||||
|
||||
/// Consumes this encoder returning the underlying reader.
|
||||
///
|
||||
/// Note that this may discard internal state of this encoder, so care should be taken
|
||||
/// to avoid losing resources when this is called.
|
||||
pub fn into_inner(self) -> $inner {
|
||||
self.inner.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncBufRead> tokio::io::AsyncRead for $name<$inner> {
|
||||
fn poll_read(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.project().inner.poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncWrite> tokio::io::AsyncWrite for $name<$inner> {
|
||||
fn poll_write(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> std::task::Poll<std::io::Result<usize>> {
|
||||
self.get_pin_mut().poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.get_pin_mut().poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.get_pin_mut().poll_shutdown(cx)
|
||||
}
|
||||
|
||||
fn poll_write_vectored(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
bufs: &[std::io::IoSlice<'_>],
|
||||
) -> std::task::Poll<std::io::Result<usize>> {
|
||||
self.get_pin_mut().poll_write_vectored(cx, bufs)
|
||||
}
|
||||
|
||||
fn is_write_vectored(&self) -> bool {
|
||||
self.get_ref().is_write_vectored()
|
||||
}
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
use crate::core::util::{_assert_send, _assert_sync};
|
||||
use core::pin::Pin;
|
||||
use tokio::io::AsyncBufRead;
|
||||
|
||||
_assert_send::<$name<Pin<Box<dyn AsyncBufRead + Send>>>>();
|
||||
_assert_sync::<$name<Pin<Box<dyn AsyncBufRead + Sync>>>>();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#[macro_use]
|
||||
mod decoder;
|
||||
#[macro_use]
|
||||
mod encoder;
|
||||
@@ -0,0 +1,10 @@
|
||||
//! Types which operate over [`AsyncBufRead`](::tokio::io::AsyncBufRead) streams, both encoders and
|
||||
//! decoders for various formats.
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod generic;
|
||||
|
||||
pub(crate) use generic::{Decoder, Encoder};
|
||||
|
||||
algos!(tokio::bufread<R>);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
//! Implementations for IO traits exported by [`tokio` v1.x](::tokio).
|
||||
|
||||
pub mod bufread;
|
||||
pub mod write;
|
||||
@@ -0,0 +1,13 @@
|
||||
// Originally sourced from `futures_util::io::buf_writer`, needs to be redefined locally so that
|
||||
// the `AsyncBufWrite` impl can access its internals, and changed a bit to make it more efficient
|
||||
// with those methods.
|
||||
|
||||
use crate::generic::write::impl_buf_writer;
|
||||
use std::{
|
||||
io,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::io::AsyncWrite;
|
||||
|
||||
impl_buf_writer!(poll_shutdown);
|
||||
@@ -0,0 +1,19 @@
|
||||
use crate::{generic::write::impl_decoder, tokio::write::BufWriter};
|
||||
use std::{
|
||||
io,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
|
||||
|
||||
impl_decoder!(poll_shutdown);
|
||||
|
||||
impl<W: AsyncRead, D> AsyncRead for Decoder<W, D> {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut ReadBuf<'_>,
|
||||
) -> Poll<io::Result<()>> {
|
||||
self.get_pin_mut().poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use crate::{generic::write::impl_encoder, tokio::write::BufWriter};
|
||||
use std::{
|
||||
io,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
|
||||
|
||||
impl_encoder!(poll_shutdown);
|
||||
|
||||
impl<W: AsyncRead, E> AsyncRead for Encoder<W, E> {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
buf: &mut ReadBuf<'_>,
|
||||
) -> Poll<io::Result<()>> {
|
||||
self.get_pin_mut().poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
mod decoder;
|
||||
mod encoder;
|
||||
|
||||
pub use self::{decoder::Decoder, encoder::Encoder};
|
||||
@@ -0,0 +1,124 @@
|
||||
macro_rules! decoder {
|
||||
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
|
||||
pin_project_lite::pin_project! {
|
||||
$(#[$attr])*
|
||||
///
|
||||
/// This structure implements an [`AsyncWrite`](tokio::io::AsyncWrite) interface and will
|
||||
/// take in compressed data and write it uncompressed to an underlying stream.
|
||||
#[derive(Debug)]
|
||||
pub struct $name<$inner> {
|
||||
#[pin]
|
||||
inner: crate::tokio::write::Decoder<$inner, crate::codecs::$name>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncWrite> $name<$inner> {
|
||||
/// Creates a new decoder which will take in compressed data and write it, uncompressed,
|
||||
/// to the given stream.
|
||||
pub fn new(read: $inner) -> $name<$inner> {
|
||||
$name {
|
||||
inner: crate::tokio::write::Decoder::new(read, crate::codecs::$name::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new decoder which will take in compressed data and write it, uncompressed,
|
||||
/// to the given stream.
|
||||
pub fn with_codec(read: $inner, codec: crate::codecs::$name) -> $name<$inner> {
|
||||
$name {
|
||||
inner: crate::tokio::write::Decoder::new(read, codec)
|
||||
}
|
||||
}
|
||||
|
||||
$($($inherent_methods)*)*
|
||||
}
|
||||
|
||||
impl<$inner> $name<$inner> {
|
||||
/// Acquires a reference to the underlying reader that this decoder is wrapping.
|
||||
pub fn get_ref(&self) -> &$inner {
|
||||
self.inner.get_ref()
|
||||
}
|
||||
|
||||
/// Acquires a mutable reference to the underlying reader that this decoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the reader which
|
||||
/// may otherwise confuse this decoder.
|
||||
pub fn get_mut(&mut self) -> &mut $inner {
|
||||
self.inner.get_mut()
|
||||
}
|
||||
|
||||
/// Acquires a pinned mutable reference to the underlying reader that this decoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the reader which
|
||||
/// may otherwise confuse this decoder.
|
||||
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
|
||||
self.project().inner.get_pin_mut()
|
||||
}
|
||||
|
||||
/// Consumes this decoder returning the underlying reader.
|
||||
///
|
||||
/// Note that this may discard internal state of this decoder, so care should be taken
|
||||
/// to avoid losing resources when this is called.
|
||||
pub fn into_inner(self) -> $inner {
|
||||
self.inner.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncWrite> tokio::io::AsyncWrite for $name<$inner> {
|
||||
fn poll_write(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> std::task::Poll<std::io::Result<usize>> {
|
||||
self.project().inner.poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.project().inner.poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.project().inner.poll_shutdown(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncRead> tokio::io::AsyncRead for $name<$inner> {
|
||||
fn poll_read(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.get_pin_mut().poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncBufRead> tokio::io::AsyncBufRead for $name<$inner> {
|
||||
fn poll_fill_buf(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>
|
||||
) -> std::task::Poll<std::io::Result<&[u8]>> {
|
||||
self.get_pin_mut().poll_fill_buf(cx)
|
||||
}
|
||||
|
||||
fn consume(self: std::pin::Pin<&mut Self>, amt: usize) {
|
||||
self.get_pin_mut().consume(amt)
|
||||
}
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
use crate::core::util::{_assert_send, _assert_sync};
|
||||
use core::pin::Pin;
|
||||
use tokio::io::AsyncWrite;
|
||||
|
||||
_assert_send::<$name<Pin<Box<dyn AsyncWrite + Send>>>>();
|
||||
_assert_sync::<$name<Pin<Box<dyn AsyncWrite + Sync>>>>();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
macro_rules! encoder {
|
||||
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
|
||||
pin_project_lite::pin_project! {
|
||||
$(#[$attr])*
|
||||
///
|
||||
/// This structure implements an [`AsyncWrite`](tokio::io::AsyncWrite) interface and will
|
||||
/// take in uncompressed data and write it compressed to an underlying stream.
|
||||
#[derive(Debug)]
|
||||
pub struct $name<$inner> {
|
||||
#[pin]
|
||||
inner: crate::tokio::write::Encoder<$inner, crate::codecs::$name>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncWrite> $name<$inner> {
|
||||
$(
|
||||
/// Creates a new encoder which will take in uncompressed data and write it
|
||||
/// compressed to the given stream.
|
||||
///
|
||||
$($inherent_methods)*
|
||||
)*
|
||||
|
||||
/// Creates a new encoder with the given codec, which will take in uncompressed data and write it,
|
||||
/// compressed, to the given stream.
|
||||
pub fn with_codec(read: $inner, codec: crate::codecs::$name) -> $name<$inner> {
|
||||
$name {
|
||||
inner: crate::tokio::write::Encoder::new(read, codec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner> $name<$inner> {
|
||||
/// Acquires a reference to the underlying writer that this encoder is wrapping.
|
||||
pub fn get_ref(&self) -> &$inner {
|
||||
self.inner.get_ref()
|
||||
}
|
||||
|
||||
/// Acquires a mutable reference to the underlying writer that this encoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the writer which
|
||||
/// may otherwise confuse this encoder.
|
||||
pub fn get_mut(&mut self) -> &mut $inner {
|
||||
self.inner.get_mut()
|
||||
}
|
||||
|
||||
/// Acquires a pinned mutable reference to the underlying writer that this encoder is
|
||||
/// wrapping.
|
||||
///
|
||||
/// Note that care must be taken to avoid tampering with the state of the writer which
|
||||
/// may otherwise confuse this encoder.
|
||||
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
|
||||
self.project().inner.get_pin_mut()
|
||||
}
|
||||
|
||||
/// Consumes this encoder returning the underlying writer.
|
||||
///
|
||||
/// Note that this may discard internal state of this encoder, so care should be taken
|
||||
/// to avoid losing resources when this is called.
|
||||
pub fn into_inner(self) -> $inner {
|
||||
self.inner.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncWrite> tokio::io::AsyncWrite for $name<$inner> {
|
||||
fn poll_write(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> std::task::Poll<std::io::Result<usize>> {
|
||||
self.project().inner.poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.project().inner.poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.project().inner.poll_shutdown(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncRead> tokio::io::AsyncRead for $name<$inner> {
|
||||
fn poll_read(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.get_pin_mut().poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<$inner: tokio::io::AsyncBufRead> tokio::io::AsyncBufRead for $name<$inner> {
|
||||
fn poll_fill_buf(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>
|
||||
) -> std::task::Poll<std::io::Result<&[u8]>> {
|
||||
self.get_pin_mut().poll_fill_buf(cx)
|
||||
}
|
||||
|
||||
fn consume(self: std::pin::Pin<&mut Self>, amt: usize) {
|
||||
self.get_pin_mut().consume(amt)
|
||||
}
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
use crate::core::util::{_assert_send, _assert_sync};
|
||||
use core::pin::Pin;
|
||||
use tokio::io::AsyncWrite;
|
||||
|
||||
_assert_send::<$name<Pin<Box<dyn AsyncWrite + Send>>>>();
|
||||
_assert_sync::<$name<Pin<Box<dyn AsyncWrite + Sync>>>>();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#[macro_use]
|
||||
mod decoder;
|
||||
#[macro_use]
|
||||
mod encoder;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//! Types which operate over [`AsyncWrite`](tokio::io::AsyncWrite) streams, both encoders and
|
||||
//! decoders for various formats.
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod generic;
|
||||
|
||||
mod buf_writer;
|
||||
|
||||
use self::{
|
||||
buf_writer::BufWriter,
|
||||
generic::{Decoder, Encoder},
|
||||
};
|
||||
use crate::generic::write::AsyncBufWrite;
|
||||
|
||||
algos!(tokio::write<W>);
|
||||
Reference in New Issue
Block a user