This is how it looks with proper formatting:
The get function declared in reqwest crate as follows.
pub async fn get<T: IntoUrl>(url: T) -> Result
In my program, I have like this
let resp1 = reqwest::blocking::get("http://debianmirror.nkn.in/debian").expect("Error in opening the url");
I'm passing &str
. How do &str
is of type T
which implements the trait IntoUrl
?.
I see the trait IntoUrl
is defined in reqwest.
which I did with the following markup:
The get function declared in reqwest crate as follows.
```
pub async fn get<T: IntoUrl>(url: T) -> Result
```
In my program, I have like this
```
let resp1 = reqwest::blocking::get("http://debianmirror.nkn.in/debian").expect("Error in opening the url");
```
I'm passing `&str`. How do `&str` is of type `T` which implements the trait `IntoUrl`?.
I see the trait `IntoUrl` is defined in reqwest.
Please take care to use proper formatting in the future. Notice that I also have single backticks around types in the post, and I avoid having empty lines in the code block.
As for your question, you can look at the IntoUrl
trait's documentation, but unfortunately reqwest uses a private type to seal the trait, which also hides the list of possible url types from the documentation. You have to actually view the source code to find the list. They give this reason for doing it like this:
This trait is "sealed", such that only types within reqwest can implement it. The reason is that it will eventually be deprecated and removed, when std::convert::TryFrom
is stabilized.
If you take a look at the source code, you will find the following impls:
impl PolyfillTryInto for Url { ... }
impl<'a> PolyfillTryInto for &'a str { ... }
impl<'a> PolyfillTryInto for &'a String { ... }
So there are three types you can use as an url:
&str
&String
Url
Any other type would have to be converted into one of the three types above first.