Skip to content

Commit f49d4bd

Browse files
authored
chore: add FromStr for Endpoint (#558)
This is particularly handy when combined with `clap::value_t`. Here's demo of it working with Clap: ```bash cargo +stable init --bin tonic-demo cd tonic-demo cat <<-EOF >> Cargo.toml clap = "*" tonic = { path = "../hyperium/tonic/tonic" } EOF cat <<-EOF > src/main.rs use clap::{value_t, App, Arg}; use tonic::transport::Endpoint; fn main() { let matches = App::new("tonic-demo") .arg(Arg::with_name("host")) .get_matches(); let x = value_t!(matches.value_of("host"), Endpoint); println!("{:?}", x); } EOF cargo +stable run -- https://127.0.0.1:443 ``` Signed-off-by: Ana Hobden <[email protected]>
1 parent 4f5e160 commit f49d4bd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tonic/src/transport/channel/endpoint.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use http::{
1313
use std::{
1414
convert::{TryFrom, TryInto},
1515
fmt,
16+
str::FromStr,
1617
time::Duration,
1718
};
1819
use tower::make::MakeConnection;
@@ -351,3 +352,11 @@ impl fmt::Debug for Endpoint {
351352
f.debug_struct("Endpoint").finish()
352353
}
353354
}
355+
356+
impl FromStr for Endpoint {
357+
type Err = InvalidUri;
358+
359+
fn from_str(s: &str) -> Result<Self, Self::Err> {
360+
Self::try_from(s.to_string())
361+
}
362+
}

0 commit comments

Comments
 (0)