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

pub trait FromForm<'f>: Sized {
    type Error;
    fn from_form_items(form_items: &mut FormItems<'f>)
                       -> Result<Self, Self::Error>; }

Trait to create an instance of some type from an HTTP form. Form requires its generic type to implement 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.

Implementing

An implementation of FromForm uses the FormItems iterator to iterate through the raw form key/value pairs. Be aware that form fields that are typically hidden from your application, such as _method, will be present while iterating.

Associated Types

The associated error to be returned when parsing fails.

Required Methods

Parses an instance of Self from the form items or returns an Error if one cannot be parsed.

Implementors