fix(transport) Do not panic when building and Endpoint with an invali… (#438)
BREAKING CHANGE: `TryFrom` API has been changed.
This commit is contained in:
@@ -50,6 +50,10 @@ impl Endpoint {
|
|||||||
|
|
||||||
/// Convert an `Endpoint` from a static string.
|
/// Convert an `Endpoint` from a static string.
|
||||||
///
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This function panics if the argument is an invalid URI.
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use tonic::transport::Endpoint;
|
/// # use tonic::transport::Endpoint;
|
||||||
/// Endpoint::from_static("https://example.com");
|
/// Endpoint::from_static("https://example.com");
|
||||||
@@ -306,24 +310,13 @@ impl TryFrom<String> for Endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&'static str> for Endpoint {
|
impl TryFrom<&'static str> for Endpoint {
|
||||||
type Error = Never;
|
type Error = InvalidUri;
|
||||||
|
|
||||||
fn try_from(t: &'static str) -> Result<Self, Self::Error> {
|
fn try_from(t: &'static str) -> Result<Self, Self::Error> {
|
||||||
Ok(Self::from_static(t))
|
Self::from_shared(t.as_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Never {}
|
|
||||||
|
|
||||||
impl std::fmt::Display for Never {
|
|
||||||
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match *self {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::error::Error for Never {}
|
|
||||||
|
|
||||||
impl fmt::Debug for Endpoint {
|
impl fmt::Debug for Endpoint {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("Endpoint").finish()
|
f.debug_struct("Endpoint").finish()
|
||||||
|
|||||||
Reference in New Issue
Block a user