Skip to content

Commit

Permalink
fix(transport) Do not panic when building and Endpoint with an invali… (
Browse files Browse the repository at this point in the history
#438)

BREAKING CHANGE: `TryFrom` API has been changed.
  • Loading branch information
alce authored Aug 31, 2020
1 parent 62c1230 commit 26ce9d1
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -306,24 +310,13 @@ impl TryFrom<String> for Endpoint {
}

impl TryFrom<&'static str> for Endpoint {
type Error = Never;
type Error = InvalidUri;

fn try_from(t: &'static str) -> Result<Self, Self::Error> {
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()
Expand Down

0 comments on commit 26ce9d1

Please sign in to comment.