pub trait FromBody: Sized {
    type Err: Error;
    fn from_body(body: Bytes, content_type: Mime) -> Result<Self, Self::Err>;
}
Expand description

This trait should be implemented for every type that can be built from an HTTP request body plus its media type.

For most use cases it is sufficient to derive this trait, you usually don’t need to manually implement this. Therefore, make sure that the first variable of your struct can be built from Bytes, and the second one can be build from Mime. If you have any additional variables, they need to be Default. This is an example of such a struct:

#[derive(FromBody, RequestBody)]
#[supported_types(mime::IMAGE_GIF, mime::IMAGE_JPEG, mime::IMAGE_PNG)]
struct RawImage {
	content: Vec<u8>,
	content_type: Mime
}

Associated Types

The error type returned by the conversion if it was unsuccessfull. When using the derive macro, there is no way to trigger an error, so std::convert::Infallible is used here. However, this might change in the future.

Required methods

Perform the conversion.

Implementors