From 26ce9d12bf1765e5a7acb07cab05b6bd75bd4e4d Mon Sep 17 00:00:00 2001 From: Juan Alvarez Date: Mon, 31 Aug 2020 09:02:40 -0500 Subject: [PATCH] =?UTF-8?q?fix(transport)=20Do=20not=20panic=20when=20buil?= =?UTF-8?q?ding=20and=20Endpoint=20with=20an=20invali=E2=80=A6=20(#438)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: `TryFrom` API has been changed. --- tonic/src/transport/channel/endpoint.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tonic/src/transport/channel/endpoint.rs b/tonic/src/transport/channel/endpoint.rs index da0d2c291..5889f64c5 100644 --- a/tonic/src/transport/channel/endpoint.rs +++ b/tonic/src/transport/channel/endpoint.rs @@ -50,6 +50,10 @@ impl Endpoint { /// Convert an `Endpoint` from a static string. /// + /// # Panics + /// + /// This function panics if the argument is an invalid URI. + /// /// ``` /// # use tonic::transport::Endpoint; /// Endpoint::from_static("https://example.com"); @@ -306,24 +310,13 @@ impl TryFrom for Endpoint { } impl TryFrom<&'static str> for Endpoint { - type Error = Never; + type Error = InvalidUri; fn try_from(t: &'static str) -> Result { - Ok(Self::from_static(t)) - } -} - -#[derive(Debug)] -pub enum Never {} - -impl std::fmt::Display for Never { - fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self {} + Self::from_shared(t.as_bytes()) } } -impl std::error::Error for Never {} - impl fmt::Debug for Endpoint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Endpoint").finish()