From 7cb1cd23625d7ac0e78cd750f9043c2ac62e37a5 Mon Sep 17 00:00:00 2001 From: tottoto Date: Thu, 16 Nov 2023 06:10:20 +0900 Subject: [PATCH] chore(tonic): Deprecate API when they only return None (#1520) --- tonic/src/request.rs | 27 ++++++++++++++++++++++++++- tonic/src/transport/mod.rs | 1 + tonic/src/transport/tls.rs | 9 +++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tonic/src/request.rs b/tonic/src/request.rs index e0295be59..5edd88c84 100644 --- a/tonic/src/request.rs +++ b/tonic/src/request.rs @@ -1,8 +1,11 @@ use crate::metadata::{MetadataMap, MetadataValue}; +#[cfg(feature = "transport")] +use crate::transport::server::TcpConnectInfo; #[cfg(all(feature = "transport", feature = "tls"))] use crate::transport::server::TlsConnectInfo; #[cfg(feature = "transport")] -use crate::transport::{server::TcpConnectInfo, Certificate}; +#[allow(deprecated)] +use crate::transport::Certificate; use crate::Extensions; #[cfg(feature = "transport")] use std::sync::Arc; @@ -207,6 +210,13 @@ impl Request { /// This will return `None` if the `IO` type used /// does not implement `Connected` or when using a unix domain socket. /// This currently only works on the server side. + #[cfg_attr( + not(feature = "transport"), + deprecated( + since = "0.10.3", + note = "`remote_addr` only returns `None` without transport feature. This API will require transport feature.", + ) + )] pub fn local_addr(&self) -> Option { #[cfg(feature = "transport")] { @@ -241,6 +251,13 @@ impl Request { /// This will return `None` if the `IO` type used /// does not implement `Connected` or when using a unix domain socket. /// This currently only works on the server side. + #[cfg_attr( + not(feature = "transport"), + deprecated( + since = "0.10.3", + note = "`remote_addr` only returns `None` without transport feature. This API will require transport feature.", + ) + )] pub fn remote_addr(&self) -> Option { #[cfg(feature = "transport")] { @@ -277,7 +294,15 @@ impl Request { /// `Some` on the server side of the `transport` server with /// TLS enabled connections. #[cfg(feature = "transport")] + #[cfg_attr( + all(feature = "transport", not(feature = "tls")), + deprecated( + since = "0.10.3", + note = "`peer_certs` only returns `None` without tls feature. This API will require tls feature.", + ) + )] #[cfg_attr(docsrs, doc(cfg(feature = "transport")))] + #[allow(deprecated)] pub fn peer_certs(&self) -> Option>> { #[cfg(feature = "tls")] { diff --git a/tonic/src/transport/mod.rs b/tonic/src/transport/mod.rs index 3fa2bc8c9..c676bfb92 100644 --- a/tonic/src/transport/mod.rs +++ b/tonic/src/transport/mod.rs @@ -103,6 +103,7 @@ pub use self::error::Error; pub use self::server::Server; #[doc(inline)] pub use self::service::grpc_timeout::TimeoutExpired; +#[allow(deprecated)] pub use self::tls::Certificate; #[doc(inline)] /// A deprecated re-export. Please use `tonic::server::NamedService` directly. diff --git a/tonic/src/transport/tls.rs b/tonic/src/transport/tls.rs index a4151c748..39fcc20c5 100644 --- a/tonic/src/transport/tls.rs +++ b/tonic/src/transport/tls.rs @@ -1,4 +1,11 @@ /// Represents a X509 certificate. +#[cfg_attr( + not(feature = "tls"), + deprecated( + since = "0.10.3", + note = "`Certificate` is used only by deprecated API without tls feature.", + ) +)] #[derive(Debug, Clone)] pub struct Certificate { pub(crate) pem: Vec, @@ -13,6 +20,7 @@ pub struct Identity { pub(crate) key: Vec, } +#[allow(deprecated)] impl Certificate { /// Parse a PEM encoded X509 Certificate. /// @@ -38,6 +46,7 @@ impl Certificate { } } +#[allow(deprecated)] impl AsRef<[u8]> for Certificate { fn as_ref(&self) -> &[u8] { self.pem.as_ref()