//! # Rocket - Code Generation //! //! This crate implements the code generation portions of Rocket. This includes //! custom derives, custom attributes, and procedural macros. The documentation //! here is purely technical. The code generation facilities are documented //! thoroughly in the [Rocket programming guide](https://rocket.rs/guide). //! //! ## Custom Attributes //! //! This crate implements the following custom attributes: //! //! * **route** //! * **get** //! * **put** //! * **post** //! * **delete** //! * **head** //! * **patch** //! * **options** //! * **error** //! //! The grammar for all _route_ attributes, including **route**, **get**, //! **put**, **post**, **delete**, **head**, **patch**, and **options** is //! defined as: //! //!
//! route := METHOD? '(' ('path' '=')? path (',' kv_param)* ')' //! //! path := URI_SEG //! | DYNAMIC_PARAM //! | '?' DYNAMIC_PARAM //! | path '/' path //! (string literal) //! //! kv_param := 'rank' '=' INTEGER //! | 'format' '=' STRING //! | 'data' '=' DYNAMIC_PARAM //! //! INTEGER := isize, as defined by Rust //! STRING := UTF-8 string literal, as defined by Rust //! IDENT := valid identifier, as defined by Rust //! //! URI_SEG := valid HTTP URI Segment //! DYNAMIC_PARAM := '<' IDENT '..'? '>' (string literal) //!//! //! Note that the **route** attribute takes a method as its first argument, //! while the remaining do not. That is, **route** looks like: //! //! #[route(GET, path = "/hello")] //! //! while the equivalent using **get** looks like: //! //! #[get("/hello")] //! //! The syntax for the **error** attribute is: //! //!
//! error := INTEGER //!//! //! A use of the `error` attribute looks like: //! //! #[error(404)] //! //! ## Custom Derives //! //! This crate implements the following custom derives: //! //! * **FromForm** //! //! ### `FromForm` //! //! The [`FromForm`] derive can be applied to structures with named fields: //! //! #[derive(FromForm)] //! struct MyStruct { //! field: usize, //! other: String //! } //! //! Each field's type is required to implement [`FromFormValue`]. The derive //! accepts one field attribute: `form`, with the following syntax: //! //!
//! form := 'field' '=' '"' IDENT '"' //! //! IDENT := valid identifier, as defined by Rust //!//! //! When applied, the attribute looks as follows: //! //! #[derive(FromForm)] //! struct MyStruct { //! field: usize, //! #[form(field = "renamed_field")] //! other: String //! } //! //! The derive generates an implementation for the [`FromForm`] trait. The //! implementation parses a form whose field names match the field names of the //! structure on which the derive was applied. Each field's value is parsed with //! the [`FromFormValue`] implementation of the field's type. The `FromForm` //! implementation succeeds only when all of the field parses succeed. //! //! The `form` field attribute can be used to direct that a different incoming //! field name is expected. In this case, the attribute's field name is used //! instead of the structure's field name when parsing a form. //! //! [`FromForm`]: /rocket/request/trait.FromForm.html //! [`FromFormValue`]: /rocket/request/trait.FromFormValue.html //! //! ## Procedural Macros //! //! This crate implements the following procedural macros: //! //! * **routes** //! * **errors** //! * **uri** //! //! The syntax for `routes!` and `errors!` is defined as: //! //!
//! macro := PATH (',' PATH)* //! //! PATH := a path, as defined by Rust //!//! //! ### Typed URIs: `uri!` //! //! The `uri!` macro creates a type-safe URI given a route and values for the //! route's URI parameters. //! //! For example, for the following route: //! //! ```rust,ignore //! #[get("/person/
//! uri := (mount ',')? PATH (':' params)? //! //! mount = STRING //! params := unnamed | named //! unnamed := EXPR (',' EXPR)* //! named := IDENT = EXPR (',' named)? //! //! EXPR := a valid Rust expression (examples: `foo()`, `12`, `"hey"`) //! IDENT := a valid Rust identifier (examples: `name`, `age`) //! STRING := an uncooked string literal, as defined by Rust (example: `"hi"`) //! PATH := a path, as defined by Rust (examples: `route`, `my_mod::route`) //!//! //! #### Semantics //! //! The `uri!` macro returns a `Uri` structure with the URI of the supplied //! route with the given values. A `uri!` invocation only succeeds if the type //! of every value in the invocation matches the type declared for the parameter //! in the given route. //! //! The [`FromUriParam`] trait is used to typecheck and perform a conversion for //! each value. If a `FromUriParam