-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from dtolnay-contrib/tonic
Expose choice of supported tonic version
- Loading branch information
Showing
3 changed files
with
33 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
use tonic::transport::server::Connected; | ||
|
||
use crate::{VsockAddr, VsockStream}; | ||
use crate::VsockAddr; | ||
|
||
/// Connection info for a Vsock Stream. | ||
/// | ||
/// See [`Connected`] for more details. | ||
/// See [`Connected`][tonic012::transport::server::Connected] for more details. | ||
/// | ||
#[cfg_attr(docsrs, doc(cfg(feature = "tonic-conn")))] | ||
#[derive(Debug, Clone, Eq, PartialEq)] | ||
pub struct VsockConnectInfo { | ||
peer_addr: Option<VsockAddr>, | ||
} | ||
|
||
#[cfg_attr(docsrs, doc(cfg(feature = "tonic-conn")))] | ||
impl VsockConnectInfo { | ||
/// Return the remote address the IO resource is connected too. | ||
pub fn peer_addr(&self) -> Option<VsockAddr> { | ||
self.peer_addr | ||
} | ||
} | ||
|
||
/// Allow consumers of VsockStream to check that it is connected and valid before use. | ||
/// | ||
#[cfg_attr(docsrs, doc(cfg(feature = "tonic-conn")))] | ||
impl Connected for VsockStream { | ||
type ConnectInfo = VsockConnectInfo; | ||
macro_rules! tonic_connected { | ||
($tonic_version:ident $cfg:literal) => { | ||
/// Allow consumers of VsockStream to check that it is connected and valid before use. | ||
/// | ||
#[cfg(feature = $cfg)] | ||
#[cfg_attr(docsrs, doc(cfg(feature = $cfg)))] | ||
impl $tonic_version::transport::server::Connected for crate::VsockStream { | ||
type ConnectInfo = VsockConnectInfo; | ||
|
||
fn connect_info(&self) -> Self::ConnectInfo { | ||
VsockConnectInfo { | ||
peer_addr: self.peer_addr().ok(), | ||
fn connect_info(&self) -> Self::ConnectInfo { | ||
VsockConnectInfo { | ||
peer_addr: self.peer_addr().ok(), | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
tonic_connected!(tonic05 "tonic05"); | ||
tonic_connected!(tonic06 "tonic06"); | ||
tonic_connected!(tonic07 "tonic07"); | ||
tonic_connected!(tonic08 "tonic08"); | ||
tonic_connected!(tonic09 "tonic09"); | ||
tonic_connected!(tonic010 "tonic010"); | ||
tonic_connected!(tonic011 "tonic011"); | ||
tonic_connected!(tonic012 "tonic012"); |