Derive Macro validify::Payload

source ·
#[derive(Payload)]
Expand description

Generates a struct with the same structure of the implementing struct with all its fields as options. This can only be used on struct that implement Validify. Any nested structs must also contain their corresponding payloads.

The payload struct is Deserializable, has From and Into impls for the original, and implements Validate.

The payload has 2 associated functions;

validify_into which will validate the payload and call Validify on the original,

and

validate_into which does the same, but calls Validate instead of Validify on the original.

Both functions return the original struct and are the preferred way of handling payloads in e.g., request handlers.

The payload can be used to represent a completely deserializable version of the struct even when some fields are missing. This can be used for more detailed descriptions of what fields are missing, along with any other validation errors.

Example:

#[derive(Debug, Clone, serde::Deserialize, validify::Validify, validify::Payload)]
struct Data {
    a: String,
    b: Option<String>
}

Expands to:

#[derive(Debug, validify::Validate, serde::Deserialize)]
struct DataPayload {
    #[validate(required)]
    a: Option<String>,
    b: Option<String>
}