Added missing "Errors" and "Panics" sections to request.rs and response.rs

This commit is contained in:
Michal Budzynski
2017-06-04 04:49:33 +02:00
parent 026dca2512
commit e3bf6756f4
2 changed files with 22 additions and 0 deletions

View File

@@ -153,6 +153,11 @@ impl RequestBuilder {
/// # Ok(())
/// # }
/// ```
///
/// # Errors
///
/// This method fails if the passed value cannot be serialized into
/// url encoded format
pub fn form<T: Serialize>(&mut self, form: &T) -> ::Result<&mut RequestBuilder> {
{
// check request_mut() before running serde
@@ -202,6 +207,11 @@ impl RequestBuilder {
/// Build a `Request`, which can be inspected, modified and executed with
/// `Client::execute()`.
///
/// # Panics
///
/// This method consumes builder internal state. It panics on an attempt to
/// reuse already consumed builder.
pub fn build(&mut self) -> Request {
self.request
.take()
@@ -209,6 +219,11 @@ impl RequestBuilder {
}
/// Constructs the Request and sends it the target URL, returning a Response.
///
/// # Errors
///
/// This method fails if there was an error while sending request,
/// redirect loop was detected or redirect limit was exhausted.
pub fn send(&mut self) -> ::Result<::Response> {
let request = self.build();
self.client.execute(request)

View File

@@ -100,6 +100,13 @@ impl Response {
/// # }
/// # }
/// ```
///
/// # Errors
///
/// This method fails whenever the response body is not in JSON format
/// or it cannot be properly deserialized to target type `T`. For more
/// details please see [`serde_json::from_reader`].
/// [`serde_json::from_reader`]: https://docs.serde.rs/serde_json/fn.from_reader.html
#[inline]
pub fn json<T: DeserializeOwned>(&mut self) -> ::Result<T> {
serde_json::from_reader(self).map_err(::error::from)