Skip to content

Commit

Permalink
Add generated code for tokio v1
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 10, 2022
1 parent 923c3f8 commit 070ed19
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
//!
Expand Down
53 changes: 53 additions & 0 deletions tests/expand/external/tokio/async_buf_read.expanded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
extern crate tokio1_crate as tokio;
use auto_enums::enum_derive;
enum Enum<A, B> {
A(A),
B(B),
}
#[allow(unsafe_code)]
impl<A, B> ::tokio::io::AsyncBufRead for Enum<A, B>
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() {}
11 changes: 11 additions & 0 deletions tests/expand/external/tokio/async_buf_read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extern crate tokio1_crate as tokio;

use auto_enums::enum_derive;

#[enum_derive(tokio1::AsyncBufRead)]
enum Enum<A, B> {
A(A),
B(B),
}

fn main() {}
38 changes: 38 additions & 0 deletions tests/expand/external/tokio/async_read.expanded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
extern crate tokio1_crate as tokio;
use auto_enums::enum_derive;
enum Enum<A, B> {
A(A),
B(B),
}
#[allow(unsafe_code)]
impl<A, B> ::tokio::io::AsyncRead for Enum<A, B>
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() {}
11 changes: 11 additions & 0 deletions tests/expand/external/tokio/async_read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extern crate tokio1_crate as tokio;

use auto_enums::enum_derive;

#[enum_derive(tokio1::AsyncRead)]
enum Enum<A, B> {
A(A),
B(B),
}

fn main() {}
56 changes: 56 additions & 0 deletions tests/expand/external/tokio/async_seek.expanded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
extern crate tokio1_crate as tokio;
use auto_enums::enum_derive;
enum Enum<A, B> {
A(A),
B(B),
}
#[allow(unsafe_code)]
impl<A, B> ::tokio::io::AsyncSeek for Enum<A, B>
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<u64>> {
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() {}
11 changes: 11 additions & 0 deletions tests/expand/external/tokio/async_seek.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extern crate tokio1_crate as tokio;

use auto_enums::enum_derive;

#[enum_derive(tokio1::AsyncSeek)]
enum Enum<A, B> {
A(A),
B(B),
}

fn main() {}
110 changes: 110 additions & 0 deletions tests/expand/external/tokio/async_write.expanded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
extern crate tokio1_crate as tokio;
use auto_enums::enum_derive;
enum Enum<A, B> {
A(A),
B(B),
}
#[allow(unsafe_code)]
impl<A, B> ::tokio::io::AsyncWrite for Enum<A, B>
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<usize>> {
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<usize>> {
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() {}
11 changes: 11 additions & 0 deletions tests/expand/external/tokio/async_write.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extern crate tokio1_crate as tokio;

use auto_enums::enum_derive;

#[enum_derive(tokio1::AsyncWrite)]
enum Enum<A, B> {
A(A),
B(B),
}

fn main() {}

0 comments on commit 070ed19

Please sign in to comment.