hyper_client_sockets/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3#[cfg(any(feature = "unix", feature = "vsock", feature = "firecracker"))]
4use std::future::Future;
5
6#[cfg(any(feature = "unix", feature = "firecracker"))]
7use std::path::Path;
8
9#[cfg(feature = "tokio-backend")]
10#[cfg_attr(docsrs, doc(cfg(feature = "tokio-backend")))]
11pub mod tokio;
12
13#[cfg(feature = "async-io-backend")]
14#[cfg_attr(docsrs, doc(cfg(feature = "async-io-backend")))]
15pub mod async_io;
16
17#[cfg(feature = "hyper-util")]
18#[cfg_attr(docsrs, doc(cfg(feature = "hyper-util")))]
19pub mod uri;
20
21#[cfg(feature = "hyper-util")]
22#[cfg_attr(docsrs, doc(cfg(feature = "hyper-util")))]
23pub mod connector;
24
25/// A [Backend] is a runtime- and reactor-agnostic way to use hyper client-side with various types of sockets.
26pub trait Backend: Clone {
27    /// An IO object representing a connected Unix socket.
28    #[cfg(feature = "unix")]
29    #[cfg_attr(docsrs, doc(cfg(feature = "unix")))]
30    type UnixIo: hyper::rt::Read + hyper::rt::Write + Send + Unpin;
31
32    /// An IO object representing a connected virtio-vsock socket.
33    #[cfg(feature = "vsock")]
34    #[cfg_attr(docsrs, doc(cfg(feature = "vsock")))]
35    type VsockIo: hyper::rt::Read + hyper::rt::Write + Send + Unpin;
36
37    /// An IO object representing a connected Firecracker socket (a specialized Unix socket).
38    #[cfg(feature = "firecracker")]
39    #[cfg_attr(docsrs, doc(cfg(feature = "firecracker")))]
40    type FirecrackerIo: hyper::rt::Read + hyper::rt::Write + Send + Unpin;
41
42    /// Connect to a Unix socket at the given [Path].
43    #[cfg(feature = "unix")]
44    #[cfg_attr(docsrs, doc(cfg(feature = "unix")))]
45    fn connect_to_unix_socket(socket_path: &Path) -> impl Future<Output = Result<Self::UnixIo, std::io::Error>> + Send;
46
47    /// Connect to a virtio-vsock socket at the given vsock address.
48    #[cfg(feature = "vsock")]
49    #[cfg_attr(docsrs, doc(cfg(feature = "vsock")))]
50    fn connect_to_vsock_socket(
51        addr: vsock::VsockAddr,
52    ) -> impl Future<Output = Result<Self::VsockIo, std::io::Error>> + Send;
53
54    /// Connect to a Firecracker socket at the given [Path], establishing a tunnel to the given
55    /// guest vsock port.
56    #[cfg(feature = "firecracker")]
57    #[cfg_attr(docsrs, doc(cfg(feature = "firecracker")))]
58    fn connect_to_firecracker_socket(
59        host_socket_path: &Path,
60        guest_port: u32,
61    ) -> impl Future<Output = Result<Self::FirecrackerIo, std::io::Error>> + Send;
62}