Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions grpc/src/credentials/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,28 @@ impl<T: ChannelCredentials> ChannelCredentials for CompositeChannelCredentials<T
}
}

impl<T> crate::credentials::dyn_wrapper::IntoDynChannelCredentials
for CompositeChannelCredentials<T>
where
T: ChannelCredentials + 'static,
T::Output<crate::rt::BoxEndpoint>: crate::rt::GrpcEndpoint,
{
fn into_dyn_creds(self) -> Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials> {
Arc::new(self) as Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials>
}
}

impl<T> crate::credentials::dyn_wrapper::IntoDynChannelCredentials
for Arc<CompositeChannelCredentials<T>>
where
T: ChannelCredentials + 'static,
T::Output<crate::rt::BoxEndpoint>: crate::rt::GrpcEndpoint,
{
fn into_dyn_creds(self) -> Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials> {
self as Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials>
}
}

#[cfg(test)]
mod tests {
use tokio::net::TcpListener;
Expand Down
12 changes: 11 additions & 1 deletion grpc/src/credentials/dyn_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type BoxEndpoint = Box<dyn GrpcEndpoint>;

// Bridge trait for type erasure.
#[async_trait]
pub(crate) trait DynChannelCredentials: Send + Sync {
pub trait DynChannelCredentials: Send + Sync {
async fn dyn_connect(
&self,
authority: &Authority,
Expand Down Expand Up @@ -121,6 +121,16 @@ impl ChannelCredentials for Arc<dyn DynChannelCredentials> {
}
}

pub trait IntoDynChannelCredentials {
fn into_dyn_creds(self) -> Arc<dyn DynChannelCredentials>;
}

impl IntoDynChannelCredentials for Arc<dyn DynChannelCredentials> {
fn into_dyn_creds(self) -> Arc<dyn DynChannelCredentials> {
self
}
}

// Bridge trait for type erasure.
#[async_trait]
pub(crate) trait DynServerCredentials: Send + Sync {
Expand Down
12 changes: 12 additions & 0 deletions grpc/src/credentials/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ impl ChannelCredentials for LocalChannelCredentials {
}
}

impl crate::credentials::dyn_wrapper::IntoDynChannelCredentials for LocalChannelCredentials {
fn into_dyn_creds(self) -> Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials> {
Arc::new(self) as Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials>
}
}

impl crate::credentials::dyn_wrapper::IntoDynChannelCredentials for Arc<LocalChannelCredentials> {
fn into_dyn_creds(self) -> Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials> {
self as Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials>
}
}

/// An implementation of [`ServerCredentials`] for local connections to pair
/// with a client using [`LocalChannelCredentials`].
#[derive(Debug, Clone, Default)]
Expand Down
4 changes: 4 additions & 0 deletions grpc/src/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
pub mod call;
pub(crate) mod client;
pub(crate) mod dyn_wrapper;
#[doc(hidden)]
pub use dyn_wrapper::DynChannelCredentials;
#[doc(hidden)]
pub use dyn_wrapper::IntoDynChannelCredentials;
mod local;
#[cfg(feature = "tls-rustls")]
pub mod rustls;
Expand Down
12 changes: 12 additions & 0 deletions grpc/src/credentials/rustls/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,15 @@ impl ChannelCredentials for RustlsChannelCredendials {
None
}
}

impl crate::credentials::dyn_wrapper::IntoDynChannelCredentials for RustlsChannelCredendials {
fn into_dyn_creds(self) -> Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials> {
Arc::new(self) as Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials>
}
}

impl crate::credentials::dyn_wrapper::IntoDynChannelCredentials for Arc<RustlsChannelCredendials> {
fn into_dyn_creds(self) -> Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials> {
self as Arc<dyn crate::credentials::dyn_wrapper::DynChannelCredentials>
}
}
Loading