Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transport) Do not panic when building and Endpoint with an invali… #438

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Changes from all commits
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
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