rocket_codegen 0.2.0

Code generation for the Rocket web framework.
docs.rs failed to build rocket_codegen-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: rocket_codegen-0.5.0

Rocket - Code Generation

This crate implements the code generation portions of Rocket. This includes custom derives, custom attributes, procedural macros, and lints. The documentation here is purely technical. The code generation facilities are documented thoroughly in the Rocket programming 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:

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:

A use of the error attribute looks like:

#[error(404)]

Custom Derives

This crate implements the following custom derives:

  • FromForm

Procedural Macros

This crate implements the following procedural macros:

  • routes
  • errors

The syntax for both of these is defined as:

Lints

This crate implements the following lints:

  • unmounted_route: defaults to warn

    emits a warning when a declared route is not mounted

  • unmanaged_state: defaults to warn

    emits a warning when a State<T> request guest is used in a mounted route without managing a value for T

Debugging Codegen

When the ROCKET_CODEGEN_DEBUG environment variable is set, this crate logs the items it has generated to the console at compile-time. For example, you might run the following to build a Rocket application with codegen logging enabled:

ROCKET_CODEGEN_DEBUG=1 cargo build