pub struct QuicConnection {
incoming: quinn::Incoming,
}
impl QuicConnection {
pub fn new(incoming: quinn::Incoming) -> Self {
Self { incoming }
}
pub fn into_incoming(self) -> quinn::Incoming {
self.incoming
}
}
impl tokio::io::AsyncRead for QuicConnection {
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<()>> {
std::task::Poll::Ready(Err(std::io::Error::other(
"QuicConnection does not support AsyncRead",
)))
}
}
impl tokio::io::AsyncWrite for QuicConnection {
fn poll_write(
self: std::pin::Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
_buf: &[u8],
) -> std::task::Poll<std::io::Result<usize>> {
std::task::Poll::Ready(Err(std::io::Error::other(
"QuicConnection does not support AsyncWrite",
)))
}
fn poll_flush(
self: std::pin::Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<std::io::Result<()>> {
std::task::Poll::Ready(Ok(()))
}
fn poll_shutdown(
self: std::pin::Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<std::io::Result<()>> {
std::task::Poll::Ready(Ok(()))
}
}
impl Unpin for QuicConnection {}
#[cfg(all(test, feature = "quic"))]
mod tests {
use super::*;
#[test]
fn test_quic_connection_type_link() {
let _ = std::mem::size_of::<QuicConnection>();
}
#[test]
fn test_quic_connection_implements_unpin() {
fn assert_unpin<T: Unpin>() {}
assert_unpin::<QuicConnection>();
}
#[test]
fn test_into_incoming_converts_to_quinn_incoming() {
let _ = |conn: QuicConnection| -> quinn::Incoming { conn.into_incoming() };
}
#[test]
fn test_quic_connection_async_read_error_message() {
let error = std::io::Error::other("QuicConnection does not support AsyncRead");
assert!(error.to_string().contains("does not support AsyncRead"));
}
#[test]
fn test_quic_connection_async_write_error_message() {
let error = std::io::Error::other("QuicConnection does not support AsyncWrite");
assert!(error.to_string().contains("does not support AsyncWrite"));
}
#[test]
fn test_quic_connection_flush_always_succeeds() {
let result = std::io::Result::Ok(());
assert!(result.is_ok());
}
#[test]
fn test_quic_connection_shutdown_always_succeeds() {
let result = std::io::Result::Ok(());
assert!(result.is_ok());
}
#[test]
fn test_quic_connection_struct_size() {
let _ = std::mem::size_of::<QuicConnection>();
}
#[test]
fn test_quic_connection_new_method_signature() {
fn _signature(_: quinn::Incoming) -> QuicConnection {
unimplemented!()
}
}
#[test]
fn test_quic_connection_size_and_alignment() {
let size = std::mem::size_of::<QuicConnection>();
let align = std::mem::align_of::<QuicConnection>();
assert!(size > 0);
assert!(align >= std::mem::align_of::<usize>());
}
#[test]
fn test_quic_connection_operations_are_designed_to_fail() {
}
#[test]
fn test_quic_connection_poll_read_signature() {
fn assert_trait_method<T: tokio::io::AsyncRead>() {}
assert_trait_method::<QuicConnection>();
}
#[test]
fn test_quic_connection_poll_write_signature() {
fn assert_trait_method<T: tokio::io::AsyncWrite>() {}
assert_trait_method::<QuicConnection>();
}
#[test]
fn test_quic_connection_poll_flush_signature() {
fn assert_trait_method<T: tokio::io::AsyncWrite>() {}
assert_trait_method::<QuicConnection>();
}
#[test]
fn test_quic_connection_poll_shutdown_signature() {
fn assert_trait_method<T: tokio::io::AsyncWrite>() {}
assert_trait_method::<QuicConnection>();
}
#[test]
fn test_quic_connection_field_access() {
assert!(std::mem::size_of::<QuicConnection>() > 0);
}
#[tokio::test]
async fn test_quic_connection_async_read_poll_behavior() {
let error = std::io::Error::other("QuicConnection does not support AsyncRead");
assert!(error.to_string().contains("does not support AsyncRead"));
}
#[tokio::test]
async fn test_quic_connection_async_write_poll_behavior() {
let error = std::io::Error::other("QuicConnection does not support AsyncWrite");
assert!(error.to_string().contains("does not support AsyncWrite"));
}
#[tokio::test]
async fn test_quic_connection_flush_poll_behavior() {
let result: std::task::Poll<std::io::Result<()>> = std::task::Poll::Ready(Ok(()));
assert!(matches!(result, std::task::Poll::Ready(Ok(_))));
}
#[tokio::test]
async fn test_quic_connection_shutdown_poll_behavior() {
let result: std::task::Poll<std::io::Result<()>> = std::task::Poll::Ready(Ok(()));
assert!(matches!(result, std::task::Poll::Ready(Ok(_))));
}
#[test]
fn test_quic_connection_unpin_guarantee() {
fn assert_unpin<T: Unpin>() {}
assert_unpin::<QuicConnection>();
assert_unpin::<std::pin::Pin<QuicConnection>>();
}
#[test]
fn test_quic_connection_send_sync_bounds() {
fn assert_send<T: Send>() {}
fn assert_sync<T: Sync>() {}
assert_send::<QuicConnection>();
assert_sync::<QuicConnection>();
}
#[test]
fn test_quic_connection_new_and_into_incoming_roundtrip() {
let _closure = |incoming: quinn::Incoming| -> quinn::Incoming {
incoming
};
fn assert_roundtrip<T: FnOnce(quinn::Incoming) -> quinn::Incoming>(_: T) {}
assert_roundtrip(_closure);
}
#[test]
fn test_quic_connection_async_read_error_kind() {
let error = std::io::Error::other("QuicConnection does not support AsyncRead");
assert_eq!(error.kind(), std::io::ErrorKind::Other);
}
#[test]
fn test_quic_connection_async_write_error_kind() {
let error = std::io::Error::other("QuicConnection does not support AsyncWrite");
assert_eq!(error.kind(), std::io::ErrorKind::Other);
}
#[tokio::test]
async fn test_quic_connection_async_read_poll_ready() {
let error = std::io::Error::other("QuicConnection does not support AsyncRead");
let poll_result = std::task::Poll::Ready::<std::io::Result<()>>(Err(error));
assert!(matches!(poll_result, std::task::Poll::Ready(Err(_))));
}
#[tokio::test]
async fn test_quic_connection_async_write_poll_ready() {
let error = std::io::Error::other("QuicConnection does not support AsyncWrite");
let poll_result = std::task::Poll::Ready::<std::io::Result<usize>>(Err(error));
assert!(matches!(poll_result, std::task::Poll::Ready(Err(_))));
}
#[test]
fn test_quic_connection_pin_mut_behavior() {
fn assert_pinned<T: Unpin>() {
}
assert_pinned::<QuicConnection>();
}
#[test]
fn test_quic_connection_into_incoming_consumes_self() {
let _signature = |conn: QuicConnection| -> quinn::Incoming { conn.into_incoming() };
}
#[test]
fn test_quic_connection_field_incoming_exists() {
let size = std::mem::size_of::<QuicConnection>();
let incoming_size = std::mem::size_of::<quinn::Incoming>();
assert!(size >= incoming_size);
}
#[test]
fn test_quic_connection_zero_copy_optimization() {
let _ = std::mem::size_of::<quinn::Incoming>();
}
#[tokio::test]
async fn test_quic_connection_multiple_poll_flush_calls() {
let result1: std::task::Poll<std::io::Result<()>> = std::task::Poll::Ready(Ok(()));
let result2: std::task::Poll<std::io::Result<()>> = std::task::Poll::Ready(Ok(()));
assert!(result1.is_ready());
assert!(result2.is_ready());
}
#[tokio::test]
async fn test_quic_connection_multiple_poll_shutdown_calls() {
let result1: std::task::Poll<std::io::Result<()>> = std::task::Poll::Ready(Ok(()));
let result2: std::task::Poll<std::io::Result<()>> = std::task::Poll::Ready(Ok(()));
assert!(result1.is_ready());
assert!(result2.is_ready());
}
#[test]
fn test_quic_connection_error_messages_are_consistent() {
let read_error = std::io::Error::other("QuicConnection does not support AsyncRead");
let write_error = std::io::Error::other("QuicConnection does not support AsyncWrite");
assert!(read_error.to_string().contains("QuicConnection"));
assert!(write_error.to_string().contains("QuicConnection"));
assert!(read_error.to_string().contains("does not support"));
assert!(write_error.to_string().contains("does not support"));
}
#[test]
fn test_quic_connection_async_read_trait_bound() {
fn assert_async_read<T: tokio::io::AsyncRead>() {}
assert_async_read::<QuicConnection>();
}
#[test]
fn test_quic_connection_async_write_trait_bound() {
fn assert_async_write<T: tokio::io::AsyncWrite>() {}
assert_async_write::<QuicConnection>();
}
#[tokio::test]
async fn test_quic_connection_poll_read_context_param() {
use std::task::{Context, Waker};
let dummy_waker = Waker::noop();
let _context = Context::from_waker(dummy_waker);
assert!(_context.waker().will_wake(dummy_waker));
}
#[test]
fn test_quic_connection_read_buf_type() {
let _ = std::mem::size_of::<tokio::io::ReadBuf<'_>>();
}
#[test]
fn test_quic_connection_write_slice_param() {
let _slice: &[u8] = &[];
assert_eq!(_slice.len(), 0);
}
#[test]
fn test_quic_connection_struct_layout() {
let size = std::mem::size_of::<QuicConnection>();
let incoming_size = std::mem::size_of::<quinn::Incoming>();
assert!(size >= incoming_size && size < incoming_size * 2);
}
#[test]
fn test_quic_connection_pin_ref_behavior() {
fn assert_pin_methods<T: Unpin>() {
}
assert_pin_methods::<QuicConnection>();
}
#[test]
fn test_quic_connection_move_semantics() {
let _move_closure = |conn: QuicConnection| -> quinn::Incoming { conn.into_incoming() };
fn assert_fn<T: FnOnce(QuicConnection) -> quinn::Incoming>(_: T) {}
assert_fn(_move_closure);
}
#[test]
fn test_quic_connection_no_shared_mutability() {
fn assert_no_interior_mutability<T: Send + Sync>() {}
assert_no_interior_mutability::<QuicConnection>();
}
#[tokio::test]
async fn test_quic_connection_error_propagation() {
let read_error = std::io::Error::other("QuicConnection does not support AsyncRead");
let write_error = std::io::Error::other("QuicConnection does not support AsyncWrite");
assert!(read_error.to_string().contains("AsyncRead"));
assert!(write_error.to_string().contains("AsyncWrite"));
}
#[test]
fn test_quic_connection_into_incoming_type() {
fn assert_return_type<T>(_: T)
where
T: std::ops::FnOnce(QuicConnection) -> quinn::Incoming,
{
}
assert_return_type(|conn| conn.into_incoming());
}
#[test]
fn test_quic_connection_wrapper_pattern() {
let inner_size = std::mem::size_of::<quinn::Incoming>();
let wrapper_size = std::mem::size_of::<QuicConnection>();
assert!(wrapper_size < inner_size * 2);
}
#[tokio::test]
async fn test_quic_connection_read_returns_immediately() {
let poll_result = std::task::Poll::Ready::<std::io::Result<()>>(Err(
std::io::Error::other("QuicConnection does not support AsyncRead"),
));
assert!(poll_result.is_ready());
}
#[tokio::test]
async fn test_quic_connection_write_returns_immediately() {
let poll_result = std::task::Poll::Ready::<std::io::Result<usize>>(Err(
std::io::Error::other("QuicConnection does not support AsyncWrite"),
));
assert!(poll_result.is_ready());
}
#[test]
fn test_quic_connection_implements_required_traits() {
fn assert_unpin<T: Unpin>() {}
fn assert_async_read<T: tokio::io::AsyncRead>() {}
fn assert_async_write<T: tokio::io::AsyncWrite>() {}
assert_unpin::<QuicConnection>();
assert_async_read::<QuicConnection>();
assert_async_write::<QuicConnection>();
}
}