Added missing "Errors" sections to client.rs and lib.rs
This commit is contained in:
@@ -116,6 +116,10 @@ struct Config {
|
|||||||
|
|
||||||
impl ClientBuilder {
|
impl ClientBuilder {
|
||||||
/// Constructs a new `ClientBuilder`
|
/// Constructs a new `ClientBuilder`
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if native TLS backend cannot be created.
|
||||||
pub fn new() -> ::Result<ClientBuilder> {
|
pub fn new() -> ::Result<ClientBuilder> {
|
||||||
let tls_connector_builder = try_!(native_tls::TlsConnector::builder());
|
let tls_connector_builder = try_!(native_tls::TlsConnector::builder());
|
||||||
Ok(ClientBuilder {
|
Ok(ClientBuilder {
|
||||||
@@ -132,10 +136,14 @@ impl ClientBuilder {
|
|||||||
|
|
||||||
/// Returns a `Client` that uses this `ClientBuilder` configuration.
|
/// Returns a `Client` that uses this `ClientBuilder` configuration.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// This consumes the internal state of the builder. Trying to use this
|
/// This method fails if native TLS backend cannot be initialized.
|
||||||
/// builder again after calling `build` will panic.
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This method consumes the internal state of the builder.
|
||||||
|
/// Trying to use this builder again after calling `build` will panic.
|
||||||
pub fn build(&mut self) -> ::Result<Client> {
|
pub fn build(&mut self) -> ::Result<Client> {
|
||||||
let config = self.take_config();
|
let config = self.take_config();
|
||||||
|
|
||||||
@@ -170,6 +178,10 @@ impl ClientBuilder {
|
|||||||
///
|
///
|
||||||
/// This can be used to connect to a server that has a self-signed
|
/// This can be used to connect to a server that has a self-signed
|
||||||
/// certificate for example.
|
/// certificate for example.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if adding root certificate was unsuccessful.
|
||||||
pub fn add_root_certificate(&mut self, cert: Certificate) -> ::Result<&mut ClientBuilder> {
|
pub fn add_root_certificate(&mut self, cert: Certificate) -> ::Result<&mut ClientBuilder> {
|
||||||
try_!(self.config_mut().tls.add_root_certificate(cert.0));
|
try_!(self.config_mut().tls.add_root_certificate(cert.0));
|
||||||
Ok(self)
|
Ok(self)
|
||||||
@@ -246,43 +258,75 @@ impl ClientBuilder {
|
|||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Constructs a new `Client`.
|
/// Constructs a new `Client`.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if native TLS backend cannot be created or initialized.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new() -> ::Result<Client> {
|
pub fn new() -> ::Result<Client> {
|
||||||
ClientBuilder::new()?.build()
|
ClientBuilder::new()?.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `ClientBuilder` to configure a `Client`.
|
/// Creates a `ClientBuilder` to configure a `Client`.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if native TLS backend cannot be created.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn builder() -> ::Result<ClientBuilder> {
|
pub fn builder() -> ::Result<ClientBuilder> {
|
||||||
ClientBuilder::new()
|
ClientBuilder::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `GET` request to a URL.
|
/// Convenience method to make a `GET` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn get<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn get<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Get, url)
|
self.request(Method::Get, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `POST` request to a URL.
|
/// Convenience method to make a `POST` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn post<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn post<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Post, url)
|
self.request(Method::Post, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `PUT` request to a URL.
|
/// Convenience method to make a `PUT` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn put<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn put<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Put, url)
|
self.request(Method::Put, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `PATCH` request to a URL.
|
/// Convenience method to make a `PATCH` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn patch<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn patch<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Patch, url)
|
self.request(Method::Patch, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `DELETE` request to a URL.
|
/// Convenience method to make a `DELETE` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn delete<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn delete<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Delete, url)
|
self.request(Method::Delete, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to make a `HEAD` request to a URL.
|
/// Convenience method to make a `HEAD` request to a URL.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn head<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
pub fn head<U: IntoUrl>(&self, url: U) -> ::Result<RequestBuilder> {
|
||||||
self.request(Method::Head, url)
|
self.request(Method::Head, url)
|
||||||
}
|
}
|
||||||
@@ -291,6 +335,10 @@ impl Client {
|
|||||||
///
|
///
|
||||||
/// Returns a `RequestBuilder`, which will allow setting headers and
|
/// Returns a `RequestBuilder`, which will allow setting headers and
|
||||||
/// request body before sending.
|
/// request body before sending.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails whenever supplied `Url` cannot be parsed.
|
||||||
pub fn request<U: IntoUrl>(&self, method: Method, url: U) -> ::Result<RequestBuilder> {
|
pub fn request<U: IntoUrl>(&self, method: Method, url: U) -> ::Result<RequestBuilder> {
|
||||||
let url = try_!(url.into_url());
|
let url = try_!(url.into_url());
|
||||||
Ok(request::builder(self.clone(), Request::new(method, url)))
|
Ok(request::builder(self.clone(), Request::new(method, url)))
|
||||||
@@ -303,6 +351,11 @@ impl Client {
|
|||||||
///
|
///
|
||||||
/// You should prefer to use the `RequestBuilder` and
|
/// You should prefer to use the `RequestBuilder` and
|
||||||
/// `RequestBuilder::send()`.
|
/// `RequestBuilder::send()`.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This method fails if there was an error while sending request,
|
||||||
|
/// redirect loop was detected or redirect limit was exhausted.
|
||||||
pub fn execute(&self, request: Request) -> ::Result<Response> {
|
pub fn execute(&self, request: Request) -> ::Result<Response> {
|
||||||
self.inner.execute_request(request)
|
self.inner.execute_request(request)
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/lib.rs
10
src/lib.rs
@@ -208,6 +208,16 @@ mod response;
|
|||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function fails if:
|
||||||
|
///
|
||||||
|
/// - native TLS backend cannot be initialized
|
||||||
|
/// - supplied `Url` cannot be parsed
|
||||||
|
/// - there was an error while sending request
|
||||||
|
/// - redirect loop was detected
|
||||||
|
/// - redirect limit was exhausted
|
||||||
pub fn get<T: IntoUrl>(url: T) -> ::Result<Response> {
|
pub fn get<T: IntoUrl>(url: T) -> ::Result<Response> {
|
||||||
Client::new()?
|
Client::new()?
|
||||||
.get(url)?
|
.get(url)?
|
||||||
|
|||||||
Reference in New Issue
Block a user