Trait HttpParser

Source
pub trait HttpParser {
    type ApiError: DeserializeOwned;
    type OutputError: From<SocketError>;

    // Required method
    fn parse_api_error(
        &self,
        status: StatusCode,
        error: Self::ApiError,
    ) -> Self::OutputError;

    // Provided method
    fn parse<Response>(
        &self,
        status: StatusCode,
        payload: &[u8],
    ) -> Result<Response, Self::OutputError>
       where Response: DeserializeOwned { ... }
}
Expand description

Utilised by a RestClient to deserialise RestRequest::Response, and upon failure parses API errors returned from the server.

Required Associated Types§

Required Methods§

Source

fn parse_api_error( &self, status: StatusCode, error: Self::ApiError, ) -> Self::OutputError

If parse fails to deserialise the Ok(Response), this function parses to parse the API Self::ApiError associated with the response.

Provided Methods§

Source

fn parse<Response>( &self, status: StatusCode, payload: &[u8], ) -> Result<Response, Self::OutputError>
where Response: DeserializeOwned,

Attempt to parse a StatusCode & bytes payload into a deserialisable Response.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§