Skip to content

chore: add FromStr for Endpoint#558

Merged
davidpdrsn merged 1 commit intohyperium:masterfrom
Hoverbear:endpoint-from-str
Feb 13, 2021
Merged

chore: add FromStr for Endpoint#558
davidpdrsn merged 1 commit intohyperium:masterfrom
Hoverbear:endpoint-from-str

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 <[email protected]>
@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.

3 participants