1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use std::future::Future;
use trust_dns_resolver::proto::error::ProtoError;
use trust_dns_resolver::proto::Executor;
use trust_dns_resolver::name_server::{
GenericConnection, GenericConnectionProvider, RuntimeProvider, Spawn,
};
use crate::net::{AsyncStdTcpStream, AsyncStdUdpSocket};
use crate::time::AsyncStdTime;
#[derive(Clone, Copy)]
pub struct AsyncStdRuntime;
impl Executor for AsyncStdRuntime {
fn new() -> Self {
AsyncStdRuntime {}
}
fn block_on<F: Future>(&mut self, future: F) -> F::Output {
async_std::task::block_on(future)
}
}
#[derive(Clone, Copy)]
pub struct AsyncStdRuntimeHandle;
impl Spawn for AsyncStdRuntimeHandle {
fn spawn_bg<F>(&mut self, future: F)
where
F: Future<Output = Result<(), ProtoError>> + Send + 'static,
{
let _join = async_std::task::spawn(future);
}
}
impl RuntimeProvider for AsyncStdRuntime {
type Handle = AsyncStdRuntimeHandle;
type Tcp = AsyncStdTcpStream;
type Timer = AsyncStdTime;
type Udp = AsyncStdUdpSocket;
}
impl AsyncStdRuntime {
#[cfg(test)]
pub(crate) fn handle(&self) -> AsyncStdRuntimeHandle {
AsyncStdRuntimeHandle
}
}
pub type AsyncStdConnection = GenericConnection;
pub type AsyncStdConnectionProvider = GenericConnectionProvider<AsyncStdRuntime>;