Trait rocket::request::FromForm [] [src]

pub trait FromForm<'f>: Sized {
    type Error;
    fn from_form_string(form_string: &'f str) -> Result<Self, Self::Error>;
}

Trait to create an instance of some type from an HTTP form. The Form type requires that its generic parameter implements this trait.

This trait can be automatically derived via the rocket_codegen plugin:

#![feature(plugin, custom_derive)]
#![plugin(rocket_codegen)]

extern crate rocket;

#[derive(FromForm)]
struct TodoTask {
    description: String,
    completed: bool
}

The type can then be parsed from incoming form data via the data parameter and Form type.

#[post("/submit", data = "<task>")]
fn submit_task(task: Form<TodoTask>) -> String {
    format!("New task: {}", task.get().description)
}

When deriving FromForm, every field in the structure must implement FromFormValue. If you implement FormForm yourself, use the FormItems iterator to iterate through the form key/value pairs.

Associated Types

The associated error to be returned when parsing fails.

Required Methods

Parses an instance of Self from a raw HTTP form string (application/x-www-form-urlencoded data) or returns an Error if one cannot be parsed.

Implementors