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

chore: add FromStr for Endpoint #558

Merged
merged 1 commit into from Feb 13, 2021

Conversation

Hoverbear
Copy link
Contributor

Motivation

This is particularly handy when combined with clap::value_t.

Here's demo of it working with Clap:

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

Solution

Add a impl FromStr for Endpoint. It clones since the s's lifetime is too short otherwise.

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 <operator@hoverbear.org>
@Hoverbear
Copy link
Contributor Author

I'm sorry -- I don't really know how to reconcile this.
image

Can you provide guidance?

@LucioFranco
Copy link
Member

@Hoverbear that was a very helpful error message from gh lol. Restarted the checks, lets see if it works this time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants