Derive Macro rocket::UriDisplayQuery[][src]

#[derive(UriDisplayQuery)]
{
    // Attributes available to this derive:
    #[field]
}

Derive for the UriDisplay<Query> trait.

The UriDisplay<Query> derive can be applied to enums and structs. When applied to enums, variants must have at least one field. When applied to structs, the struct must have at least one field.

#[derive(UriDisplayQuery)]
enum Kind {
    A(String),
    B(usize),
}

#[derive(UriDisplayQuery)]
struct MyStruct {
    name: String,
    id: usize,
    kind: Kind,
}

Each field’s type is required to implement UriDisplay<Query>.

The derive generates an implementation of the UriDisplay<Query> trait. The implementation calls Formatter::write_named_value() for every named field, using the field’s name (unless overridden, explained next) as the name parameter, and Formatter::write_value() for every unnamed field in the order the fields are declared.

The derive accepts one field attribute: field, with the following syntax:

field := 'name' '=' '"' IDENT '"'

IDENT := valid identifier, as defined by Rust

When applied, the attribute looks as follows:

#[derive(UriDisplayQuery)]
struct MyStruct {
    name: String,
    id: usize,
    #[field(name = "type")]
    kind: Kind,
}

The field attribute directs that a different field name be used when calling Formatter::write_named_value() for the given field. The value of the name attribute is used instead of the structure’s actual field name. In the example above, the field MyStruct::kind is rendered with a name of type.