From 070ed1909ade596340a58513eba7cb69959b519b Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 10 Dec 2022 23:51:23 +0900 Subject: [PATCH] Add generated code for tokio v1 --- src/lib.rs | 8 +- .../external/tokio/async_buf_read.expanded.rs | 53 +++++++++ tests/expand/external/tokio/async_buf_read.rs | 11 ++ .../external/tokio/async_read.expanded.rs | 38 ++++++ tests/expand/external/tokio/async_read.rs | 11 ++ .../external/tokio/async_seek.expanded.rs | 56 +++++++++ tests/expand/external/tokio/async_seek.rs | 11 ++ .../external/tokio/async_write.expanded.rs | 110 ++++++++++++++++++ tests/expand/external/tokio/async_write.rs | 11 ++ 9 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 tests/expand/external/tokio/async_buf_read.expanded.rs create mode 100644 tests/expand/external/tokio/async_buf_read.rs create mode 100644 tests/expand/external/tokio/async_read.expanded.rs create mode 100644 tests/expand/external/tokio/async_read.rs create mode 100644 tests/expand/external/tokio/async_seek.expanded.rs create mode 100644 tests/expand/external/tokio/async_seek.rs create mode 100644 tests/expand/external/tokio/async_write.expanded.rs create mode 100644 tests/expand/external/tokio/async_write.rs diff --git a/src/lib.rs b/src/lib.rs index 97d98a52..e68f4082 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -712,10 +712,10 @@ //! //! ### [tokio v1][tokio1] *(requires `"tokio1"` crate feature)* //! -//! - [`tokio1::AsyncRead`](https://docs.rs/tokio/1/tokio/io/trait.AsyncRead.html) -//! - [`tokio1::AsyncWrite`](https://docs.rs/tokio/1/tokio/io/trait.AsyncWrite.html) -//! - [`tokio1::AsyncSeek`](https://docs.rs/tokio/1/tokio/io/trait.AsyncSeek.html) -//! - [`tokio1::AsyncBufRead`](https://docs.rs/tokio/1/tokio/io/trait.AsyncBufRead.html) +//! - [`tokio1::AsyncRead`](https://docs.rs/tokio/1/tokio/io/trait.AsyncRead.html) - [example](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_read.rs) | [generated code](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_read.expanded.rs) +//! - [`tokio1::AsyncWrite`](https://docs.rs/tokio/1/tokio/io/trait.AsyncWrite.html) - [example](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_write.rs) | [generated code](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_write.expanded.rs) +//! - [`tokio1::AsyncSeek`](https://docs.rs/tokio/1/tokio/io/trait.AsyncSeek.html) - [example](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_seek.rs) | [generated code](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_seek.expanded.rs) +//! - [`tokio1::AsyncBufRead`](https://docs.rs/tokio/1/tokio/io/trait.AsyncBufRead.html) - [example](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_buf_read.rs) | [generated code](https://github.com/taiki-e/auto_enums/blob/HEAD/tests/expand/external/tokio/async_buf_read.expanded.rs) //! //! ### [tokio v0.3][tokio03] *(requires `"tokio03"` crate feature)* //! diff --git a/tests/expand/external/tokio/async_buf_read.expanded.rs b/tests/expand/external/tokio/async_buf_read.expanded.rs new file mode 100644 index 00000000..0fe44283 --- /dev/null +++ b/tests/expand/external/tokio/async_buf_read.expanded.rs @@ -0,0 +1,53 @@ +extern crate tokio1_crate as tokio; +use auto_enums::enum_derive; +enum Enum { + A(A), + B(B), +} +#[allow(unsafe_code)] +impl ::tokio::io::AsyncBufRead for Enum +where + A: ::tokio::io::AsyncBufRead, + B: ::tokio::io::AsyncBufRead, +{ + fn poll_fill_buf<'__a>( + self: ::core::pin::Pin<&'__a mut Self>, + cx: &mut ::core::task::Context<'_>, + ) -> ::core::task::Poll<::std::io::Result<&'__a [u8]>> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncBufRead::poll_fill_buf( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncBufRead::poll_fill_buf( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + } + } + } + fn consume(self: ::core::pin::Pin<&mut Self>, amt: usize) { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncBufRead::consume( + ::core::pin::Pin::new_unchecked(x), + amt, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncBufRead::consume( + ::core::pin::Pin::new_unchecked(x), + amt, + ) + } + } + } + } +} +fn main() {} diff --git a/tests/expand/external/tokio/async_buf_read.rs b/tests/expand/external/tokio/async_buf_read.rs new file mode 100644 index 00000000..692e5cfa --- /dev/null +++ b/tests/expand/external/tokio/async_buf_read.rs @@ -0,0 +1,11 @@ +extern crate tokio1_crate as tokio; + +use auto_enums::enum_derive; + +#[enum_derive(tokio1::AsyncBufRead)] +enum Enum { + A(A), + B(B), +} + +fn main() {} diff --git a/tests/expand/external/tokio/async_read.expanded.rs b/tests/expand/external/tokio/async_read.expanded.rs new file mode 100644 index 00000000..28695bfe --- /dev/null +++ b/tests/expand/external/tokio/async_read.expanded.rs @@ -0,0 +1,38 @@ +extern crate tokio1_crate as tokio; +use auto_enums::enum_derive; +enum Enum { + A(A), + B(B), +} +#[allow(unsafe_code)] +impl ::tokio::io::AsyncRead for Enum +where + A: ::tokio::io::AsyncRead, + B: ::tokio::io::AsyncRead, +{ + fn poll_read( + self: ::core::pin::Pin<&mut Self>, + cx: &mut ::core::task::Context<'_>, + buf: &mut ::tokio::io::ReadBuf<'_>, + ) -> ::core::task::Poll<::std::io::Result<()>> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncRead::poll_read( + ::core::pin::Pin::new_unchecked(x), + cx, + buf, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncRead::poll_read( + ::core::pin::Pin::new_unchecked(x), + cx, + buf, + ) + } + } + } + } +} +fn main() {} diff --git a/tests/expand/external/tokio/async_read.rs b/tests/expand/external/tokio/async_read.rs new file mode 100644 index 00000000..df7d5939 --- /dev/null +++ b/tests/expand/external/tokio/async_read.rs @@ -0,0 +1,11 @@ +extern crate tokio1_crate as tokio; + +use auto_enums::enum_derive; + +#[enum_derive(tokio1::AsyncRead)] +enum Enum { + A(A), + B(B), +} + +fn main() {} diff --git a/tests/expand/external/tokio/async_seek.expanded.rs b/tests/expand/external/tokio/async_seek.expanded.rs new file mode 100644 index 00000000..6f183fd9 --- /dev/null +++ b/tests/expand/external/tokio/async_seek.expanded.rs @@ -0,0 +1,56 @@ +extern crate tokio1_crate as tokio; +use auto_enums::enum_derive; +enum Enum { + A(A), + B(B), +} +#[allow(unsafe_code)] +impl ::tokio::io::AsyncSeek for Enum +where + A: ::tokio::io::AsyncSeek, + B: ::tokio::io::AsyncSeek, +{ + fn start_seek( + self: ::core::pin::Pin<&mut Self>, + pos: ::std::io::SeekFrom, + ) -> ::std::io::Result<()> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncSeek::start_seek( + ::core::pin::Pin::new_unchecked(x), + pos, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncSeek::start_seek( + ::core::pin::Pin::new_unchecked(x), + pos, + ) + } + } + } + } + fn poll_complete( + self: ::core::pin::Pin<&mut Self>, + cx: &mut ::core::task::Context<'_>, + ) -> ::core::task::Poll<::std::io::Result> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncSeek::poll_complete( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncSeek::poll_complete( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + } + } + } +} +fn main() {} diff --git a/tests/expand/external/tokio/async_seek.rs b/tests/expand/external/tokio/async_seek.rs new file mode 100644 index 00000000..b5b5c309 --- /dev/null +++ b/tests/expand/external/tokio/async_seek.rs @@ -0,0 +1,11 @@ +extern crate tokio1_crate as tokio; + +use auto_enums::enum_derive; + +#[enum_derive(tokio1::AsyncSeek)] +enum Enum { + A(A), + B(B), +} + +fn main() {} diff --git a/tests/expand/external/tokio/async_write.expanded.rs b/tests/expand/external/tokio/async_write.expanded.rs new file mode 100644 index 00000000..b8faa931 --- /dev/null +++ b/tests/expand/external/tokio/async_write.expanded.rs @@ -0,0 +1,110 @@ +extern crate tokio1_crate as tokio; +use auto_enums::enum_derive; +enum Enum { + A(A), + B(B), +} +#[allow(unsafe_code)] +impl ::tokio::io::AsyncWrite for Enum +where + A: ::tokio::io::AsyncWrite, + B: ::tokio::io::AsyncWrite, +{ + fn poll_write( + self: ::core::pin::Pin<&mut Self>, + cx: &mut ::core::task::Context<'_>, + buf: &[u8], + ) -> ::core::task::Poll<::std::io::Result> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncWrite::poll_write( + ::core::pin::Pin::new_unchecked(x), + cx, + buf, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncWrite::poll_write( + ::core::pin::Pin::new_unchecked(x), + cx, + buf, + ) + } + } + } + } + fn poll_flush( + self: ::core::pin::Pin<&mut Self>, + cx: &mut ::core::task::Context<'_>, + ) -> ::core::task::Poll<::std::io::Result<()>> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncWrite::poll_flush( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncWrite::poll_flush( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + } + } + } + fn poll_shutdown( + self: ::core::pin::Pin<&mut Self>, + cx: &mut ::core::task::Context<'_>, + ) -> ::core::task::Poll<::std::io::Result<()>> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncWrite::poll_shutdown( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncWrite::poll_shutdown( + ::core::pin::Pin::new_unchecked(x), + cx, + ) + } + } + } + } + fn poll_write_vectored( + self: ::core::pin::Pin<&mut Self>, + cx: &mut ::core::task::Context<'_>, + bufs: &[::std::io::IoSlice<'_>], + ) -> ::core::task::Poll<::std::io::Result> { + unsafe { + match self.get_unchecked_mut() { + Enum::A(x) => { + ::tokio::io::AsyncWrite::poll_write_vectored( + ::core::pin::Pin::new_unchecked(x), + cx, + bufs, + ) + } + Enum::B(x) => { + ::tokio::io::AsyncWrite::poll_write_vectored( + ::core::pin::Pin::new_unchecked(x), + cx, + bufs, + ) + } + } + } + } + fn is_write_vectored(&self) -> bool { + match self { + Enum::A(x) => ::tokio::io::AsyncWrite::is_write_vectored(x), + Enum::B(x) => ::tokio::io::AsyncWrite::is_write_vectored(x), + } + } +} +fn main() {} diff --git a/tests/expand/external/tokio/async_write.rs b/tests/expand/external/tokio/async_write.rs new file mode 100644 index 00000000..c38dca60 --- /dev/null +++ b/tests/expand/external/tokio/async_write.rs @@ -0,0 +1,11 @@ +extern crate tokio1_crate as tokio; + +use auto_enums::enum_derive; + +#[enum_derive(tokio1::AsyncWrite)] +enum Enum { + A(A), + B(B), +} + +fn main() {}