Skip to main content

DeserializeWith

Trait DeserializeWith 

Source
pub trait DeserializeWith<F>: Sized
where F: Format,
{ // Required method fn deserialize_with(body: ResponseBody) -> Result<Self, Error>; }
Expand description

A trait used to describe a type that can be deserialized using the specified Format.

This trait defines the deserialize_with method, which takes a ResponseBody and returns the deserialized value. The F type parameter allows for different implementations of the deserialize_with method based on the specific Format marker type used.

Defining our own trait allows us to implement it on foreign types and better customize deserialization for different scenarios.

§Notes

This trait does not define a default implementation using Format::deserialize; otherwise, NoFormat would inadvertently implement Response::into_body for non-deserializable types.

Required Methods§

Source

fn deserialize_with(body: ResponseBody) -> Result<Self, Error>

Deserialize the response body using the specified format.

§Arguments
  • body - The response body to deserialize.
§Returns

A Result containing the deserialized value of type Self, or an error if deserialization fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<D> DeserializeWith<JsonFormat> for D

Available on crate feature json only.

Implements DeserializeWith<JsonFormat> for an arbitrary type D that implements serde::de::DeserializeOwned by deserializing the response body to the specified type using serde_json.

Source§

impl<D> DeserializeWith<XmlFormat> for D

Available on crate feature xml only.