Skip to content

Commit

Permalink
Wrap AsyncStdRuntime in an inline module, in place
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n authored and djc committed Jan 24, 2024
1 parent 3fded56 commit b2e0667
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions quinn/src/runtime/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@ use async_io::{Async, Timer};

use super::{AsyncTimer, AsyncUdpSocket, Runtime};

/// A Quinn runtime for async-std
#[derive(Debug)]
pub struct AsyncStdRuntime;
#[cfg(feature = "async-std")]
pub use self::async_std::AsyncStdRuntime;

impl Runtime for AsyncStdRuntime {
fn new_timer(&self, t: Instant) -> Pin<Box<dyn AsyncTimer>> {
Box::pin(Timer::at(t))
}
#[cfg(feature = "async-std")]
mod async_std {
use super::*;

fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>) {
async_std::task::spawn(future);
}
/// A Quinn runtime for async-std
#[derive(Debug)]
pub struct AsyncStdRuntime;

impl Runtime for AsyncStdRuntime {
fn new_timer(&self, t: Instant) -> Pin<Box<dyn AsyncTimer>> {
Box::pin(Timer::at(t))
}

fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>) {
::async_std::task::spawn(future);
}

fn wrap_udp_socket(&self, sock: std::net::UdpSocket) -> io::Result<Arc<dyn AsyncUdpSocket>> {
Ok(Arc::new(UdpSocket::new(sock)?))
fn wrap_udp_socket(
&self,
sock: std::net::UdpSocket,
) -> io::Result<Arc<dyn AsyncUdpSocket>> {
Ok(Arc::new(UdpSocket::new(sock)?))
}
}
}

Expand Down

0 comments on commit b2e0667

Please sign in to comment.