How to include multiple connector in a RestClient

Hi team,

I'm trying to build a rest client with hyper, with https & http support. But I'd like to avoid multiple connector in my struct, is that possible?

For example, for the following code, I'd like to only have one client field in the struct.

pub struct RestClient { 
     base_url: String,
     auth_info: String,
     scheme: RestScheme,
     http_client: hyper::Client<TimeoutConnector<HttpConnector>>,
     https_client: hyper::Client<TimeoutConnector<HttpsConnector<HttpConnector>>>,

If you want to support both schemes, you will need two connectors. That's unavoidable.

If you want to support one scheme at a time, you can use enum to have one field that stores either one of two types.

1 Like

Ok, thanks :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.