Function elastic_reqwest::parse [] [src]

pub fn parse<T>() -> Parse<T> where
    T: IsOk + DeserializeOwned

Try parse a http response into a concrete type.

Parsing is split between two calls:

  • parse where you can specify the response type
  • from_slice/from_reader wher you can specify the kind of body to read from

The reason for splitting the functions is so we can infer the types of arguments to from_slice and from_reader, but provide the concrete response type in cases it can't be inferred.

Examples

Provide an explicit response type in the parse function:

let get_response = parse::<GetResponseOf<Value>>().from_slice(response_status, response_body);

Provide an explicit response type on the result ident:

let get_response: Result<GetResponseOf<Value>, ResponseError> = parse().from_slice(response_status, response_body);

If Rust can infer the concrete response type then you can avoid specifying it at all:

let get_response = parse().from_slice(response_status, response_body);