forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.rs
More file actions
55 lines (45 loc) · 1.38 KB
/
Copy pathruntime.rs
File metadata and controls
55 lines (45 loc) · 1.38 KB
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
use std::io;
#[cfg(unix)]
use std::path::Path;
#[cfg(feature = "async")]
use futures_util::future::BoxFuture;
use sqlx_core::Runtime;
use super::stream::{TcpStream, UnixStream};
/// Uses the `std::net` primitives to implement a blocking runtime for SQLx.
#[derive(Debug)]
pub struct Blocking(sqlx_core::Blocking);
impl Runtime for Blocking {
#[doc(hidden)]
type TcpStream = TcpStream;
#[doc(hidden)]
#[cfg(unix)]
type UnixStream = UnixStream;
#[doc(hidden)]
fn connect_tcp(host: &str, port: u16) -> io::Result<Self::TcpStream>
where
Self: sqlx_core::blocking::Runtime,
{
sqlx_core::Blocking::connect_tcp(host, port).map(TcpStream)
}
#[doc(hidden)]
#[cfg(unix)]
fn connect_unix(path: &Path) -> io::Result<Self::UnixStream>
where
Self: sqlx_core::blocking::Runtime,
{
sqlx_core::Blocking::connect_unix(path).map(UnixStream)
}
#[doc(hidden)]
#[cfg(feature = "async")]
fn connect_tcp_async(_host: &str, _port: u16) -> BoxFuture<'_, io::Result<Self::TcpStream>> {
// UNREACHABLE: where Self: Async
unreachable!()
}
#[doc(hidden)]
#[cfg(feature = "async")]
fn connect_unix_async(_path: &Path) -> BoxFuture<'_, io::Result<Self::UnixStream>> {
// UNREACHABLE: where Self: Async
unreachable!()
}
}
impl sqlx_core::blocking::Runtime for Blocking {}