Crate rocket_enumform[][src]

Expand description

Rocket extension to permit enums in application/x-www-form-urlencoded forms This crate is a workaround for https://github.com/SergioBenitez/Rocket/issues/1937.

It is derived from the included serde_json implementation in rocket.

#[derive(Debug, Deserialize)]
#[serde(tag = "type")]
enum Body {
    #[serde(rename = "variant_one")]
    VariantOne(VariantOne),
    #[serde(rename = "variant_two")]
    VariantTwo(VariantTwo),
}

#[derive(Debug, Deserialize)]
struct VariantOne {
    content_one: String
}

#[derive(Debug, Deserialize)]
struct VariantTwo {
    content_two: String
}

#[post("/form", format = "form", data = "<data>")]
fn body(data: UrlEncoded<Body>) -> String { format!("{:?}", data) }

status

Works but not tested, nor have local testing affordances been added yet.

Structs

The UrlEncoded guard: easily consume x-www-form-urlencoded requests.

Enums

Error returned by the UrlEncoded guard when deserialization fails.

Functions

Deserialize an instance of type T from bytes of UrlEncoded text.

Deserialize an instance of type T from a string of UrlEncoded text.