")]
fn user(id: Uuid) -> String {
format!("We found: {}", id)
}
You can also use the `Uuid` as a form value, including in query strings:
use rocket::serde::uuid::Uuid;
#[get("/user?")]
fn user(id: Uuid) -> String {
format!("User ID: {}", id)
}
Additionally, `Uuid` implements `UriDisplay` for all `P`. As such, route URIs including `Uuid`s can be generated in a type-safe manner:
use rocket::serde::uuid::Uuid;
use rocket::response::Redirect;
#[get("/user/")]
fn user(id: Uuid) -> String {
format!("User ID: {}", id)
}
#[get("/user?")]
fn old_user_path(id: Uuid) -> Redirect {
Redirect::to(uri!(user(id)))
}
[§](https://api.rocket.rs/v0.5/rocket/serde/uuid/index.html#extra-features)
Extra Features
------------------------------------------------------------------------------------------
The [`uuid`](https://docs.rs/uuid/1)
crate exposes extra `v{n}` features for generating UUIDs which are not enabled by Rocket. To enable these features, depend on `uuid` directly. The extra functionality can be accessed via both `rocket::serde::uuid::Uuid` or the direct `uuid::Uuid`; the types are one and the same.
[dependencies.uuid]
version = "1"
features = ["v1", "v4"]
Modules[§](https://api.rocket.rs/v0.5/rocket/serde/uuid/index.html#modules)
----------------------------------------------------------------------------
[fmt](https://api.rocket.rs/v0.5/rocket/serde/uuid/fmt/index.html "mod rocket::serde::uuid::fmt")
Adapters for alternative string formats.
Macros[§](https://api.rocket.rs/v0.5/rocket/serde/uuid/index.html#macros)
--------------------------------------------------------------------------
[uuid](https://api.rocket.rs/v0.5/rocket/serde/uuid/macro.uuid.html "macro rocket::serde::uuid::uuid")
Parse [`Uuid`](https://docs.rs/uuid/*/uuid/struct.Uuid.html)
s from string literals at compile time.
Structs[§](https://api.rocket.rs/v0.5/rocket/serde/uuid/index.html#structs)
----------------------------------------------------------------------------
[Builder](https://api.rocket.rs/v0.5/rocket/serde/uuid/struct.Builder.html "struct rocket::serde::uuid::Builder")
A builder for creating a UUID.
[Error](https://api.rocket.rs/v0.5/rocket/serde/uuid/struct.Error.html "struct rocket::serde::uuid::Error")
Error returned on [`FromParam`](https://api.rocket.rs/v0.5/rocket/request/trait.FromParam.html "trait rocket::request::FromParam")
or [`FromFormField`](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")
failures.
[Uuid](https://api.rocket.rs/v0.5/rocket/serde/uuid/struct.Uuid.html "struct rocket::serde::uuid::Uuid")
A Universally Unique Identifier (UUID).
Enums[§](https://api.rocket.rs/v0.5/rocket/serde/uuid/index.html#enums)
------------------------------------------------------------------------
[Variant](https://api.rocket.rs/v0.5/rocket/serde/uuid/enum.Variant.html "enum rocket::serde::uuid::Variant")
The reserved variants of UUIDs.
[Version](https://api.rocket.rs/v0.5/rocket/serde/uuid/enum.Version.html "enum rocket::serde::uuid::Version")
The version of the UUID, denoting the generating algorithm.
Type Aliases[§](https://api.rocket.rs/v0.5/rocket/serde/uuid/index.html#types)
-------------------------------------------------------------------------------
[Bytes](https://api.rocket.rs/v0.5/rocket/serde/uuid/type.Bytes.html "type rocket::serde::uuid::Bytes")
A 128-bit (16 byte) buffer containing the UUID.
---
# rocket::serde::json - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module json](https://api.rocket.rs/v0.5/rocket/serde/json/index.html#)
------------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
::[serde](https://api.rocket.rs/v0.5/rocket/serde/index.html)
Module json Copy item path
==========================
[Source](https://api.rocket.rs/v0.5/src/rocket/serde/json.rs.html#1-654)
[Search](https://api.rocket.rs/v0.5/rocket/serde/json/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Available on **crate feature `json`** only.
Expand description
Automatic JSON (de)serialization support.
See [`Json`](https://api.rocket.rs/v0.5/rocket/serde/json/struct.Json.html "struct rocket::serde::json::Json")
for details.
[§](https://api.rocket.rs/v0.5/rocket/serde/json/index.html#enabling)
Enabling
------------------------------------------------------------------------------
This module is only available when the `json` feature is enabled. Enable it in `Cargo.toml` as follows:
[dependencies.rocket]
version = "0.5.1"
features = ["json"]
[§](https://api.rocket.rs/v0.5/rocket/serde/json/index.html#testing)
Testing
----------------------------------------------------------------------------
The [`LocalRequest`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalRequest.html "struct rocket::local::blocking::LocalRequest")
and [`LocalResponse`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalResponse.html "struct rocket::local::blocking::LocalResponse")
types provide [`json()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalRequest.html#method.json "method rocket::local::blocking::LocalRequest::json")
and [`into_json()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalResponse.html#method.into_json "method rocket::local::blocking::LocalResponse::into_json")
methods to create a request with serialized JSON and deserialize a response as JSON, respectively.
Macros[§](https://api.rocket.rs/v0.5/rocket/serde/json/index.html#macros)
--------------------------------------------------------------------------
[json](https://api.rocket.rs/v0.5/rocket/serde/json/macro.json.html "macro rocket::serde::json::json")
`nightly`
A macro to create ad-hoc JSON serializable values using JSON syntax.
Structs[§](https://api.rocket.rs/v0.5/rocket/serde/json/index.html#structs)
----------------------------------------------------------------------------
[Json](https://api.rocket.rs/v0.5/rocket/serde/json/struct.Json.html "struct rocket::serde::json::Json")
The JSON guard: easily consume and return JSON.
Enums[§](https://api.rocket.rs/v0.5/rocket/serde/json/index.html#enums)
------------------------------------------------------------------------
[Error](https://api.rocket.rs/v0.5/rocket/serde/json/enum.Error.html "enum rocket::serde::json::Error")
Error returned by the [`Json`](https://api.rocket.rs/v0.5/rocket/serde/json/struct.Json.html "struct rocket::serde::json::Json")
guard when JSON deserialization fails.
[Value](https://api.rocket.rs/v0.5/rocket/serde/json/enum.Value.html "enum rocket::serde::json::Value")
An arbitrary JSON value as returned by [`json!`](https://api.rocket.rs/v0.5/rocket/serde/json/macro.json.html "macro rocket::serde::json::json")
.
Functions[§](https://api.rocket.rs/v0.5/rocket/serde/json/index.html#functions)
--------------------------------------------------------------------------------
[from\_slice](https://api.rocket.rs/v0.5/rocket/serde/json/fn.from_slice.html "fn rocket::serde::json::from_slice")
Deserialize an instance of type `T` from bytes of JSON text.
[from\_str](https://api.rocket.rs/v0.5/rocket/serde/json/fn.from_str.html "fn rocket::serde::json::from_str")
Deserialize an instance of type `T` from a string of JSON text.
[from\_value](https://api.rocket.rs/v0.5/rocket/serde/json/fn.from_value.html "fn rocket::serde::json::from_value")
Interpret a [`Value`](https://api.rocket.rs/v0.5/rocket/serde/json/enum.Value.html "enum rocket::serde::json::Value")
as an instance of type `T`.
[to\_pretty\_string](https://api.rocket.rs/v0.5/rocket/serde/json/fn.to_pretty_string.html "fn rocket::serde::json::to_pretty_string")
Serialize a `T` into a JSON string with “pretty” formatted representation.
[to\_string](https://api.rocket.rs/v0.5/rocket/serde/json/fn.to_string.html "fn rocket::serde::json::to_string")
Serialize a `T` into a JSON string with compact representation.
[to\_value](https://api.rocket.rs/v0.5/rocket/serde/json/fn.to_value.html "fn rocket::serde::json::to_value")
Convert a `T` into a [`Value`](https://api.rocket.rs/v0.5/rocket/serde/json/enum.Value.html "enum rocket::serde::json::Value")
, an opaque value representing JSON data.
---
# rocket::fairing - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module fairing](https://api.rocket.rs/v0.5/rocket/fairing/index.html#)
------------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module fairing Copy item path
=============================
[Source](https://api.rocket.rs/v0.5/src/rocket/fairing/mod.rs.html#1-567)
[Search](https://api.rocket.rs/v0.5/rocket/fairing/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Fairings: callbacks at launch, liftoff, request, and response time.
Fairings allow for structured interposition at various points in the application lifetime. Fairings can be seen as a restricted form of “middleware”. A fairing is an arbitrary structure with methods representing callbacks that Rocket will run at requested points in a program. You can use fairings to rewrite or record information about requests and responses, or to perform an action once a Rocket application has launched.
To learn more about writing a fairing, see the [`Fairing`](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html "trait rocket::fairing::Fairing")
trait documentation. You can also use [`AdHoc`](https://api.rocket.rs/v0.5/rocket/fairing/struct.AdHoc.html "struct rocket::fairing::AdHoc")
to create a fairing on-the-fly from a closure or function.
### [§](https://api.rocket.rs/v0.5/rocket/fairing/index.html#attaching)
Attaching
You must inform Rocket about fairings that you wish to be active by calling [`Rocket::attach()`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html#method.attach "method rocket::Rocket::attach")
method on the application’s [`Rocket`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html "struct rocket::Rocket")
instance and passing in the appropriate [`Fairing`](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html "trait rocket::fairing::Fairing")
. For instance, to attach fairings named `req_fairing` and `res_fairing` to a new Rocket instance, you might write:
let rocket = rocket::build()
.attach(req_fairing)
.attach(res_fairing);
Once a fairing is attached, Rocket will execute it at the appropriate time, which varies depending on the fairing implementation. See the [`Fairing`](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html "trait rocket::fairing::Fairing")
trait documentation for more information on the dispatching of fairing methods.
### [§](https://api.rocket.rs/v0.5/rocket/fairing/index.html#ordering)
Ordering
`Fairing`s are executed in the order in which they are attached: the first attached fairing has its callbacks executed before all others. A fairing can be attached any number of times. Except for [singleton fairings](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html#singletons "trait rocket::fairing::Fairing")
, all attached instances are polled at runtime. Fairing callbacks may not be commutative; the order in which fairings are attached may be significant. It is thus important to communicate specific fairing functionality clearly.
Furthermore, a `Fairing` should take care to act locally so that the actions of other `Fairings` are not jeopardized. For instance, unless it is made abundantly clear, a fairing should not rewrite every request.
Structs[§](https://api.rocket.rs/v0.5/rocket/fairing/index.html#structs)
-------------------------------------------------------------------------
[AdHoc](https://api.rocket.rs/v0.5/rocket/fairing/struct.AdHoc.html "struct rocket::fairing::AdHoc")
A ad-hoc fairing that can be created from a function or closure.
[Info](https://api.rocket.rs/v0.5/rocket/fairing/struct.Info.html "struct rocket::fairing::Info")
Information about a [`Fairing`](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html "trait rocket::fairing::Fairing")
.
[Kind](https://api.rocket.rs/v0.5/rocket/fairing/struct.Kind.html "struct rocket::fairing::Kind")
A bitset representing the kinds of callbacks a [`Fairing`](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html "trait rocket::fairing::Fairing")
wishes to receive.
Traits[§](https://api.rocket.rs/v0.5/rocket/fairing/index.html#traits)
-----------------------------------------------------------------------
[Fairing](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html "trait rocket::fairing::Fairing")
Trait implemented by fairings: Rocket’s structured middleware.
Type Aliases[§](https://api.rocket.rs/v0.5/rocket/fairing/index.html#types)
----------------------------------------------------------------------------
[Result](https://api.rocket.rs/v0.5/rocket/fairing/type.Result.html "type rocket::fairing::Result")
A type alias for the return `Result` type of [`Fairing::on_ignite()`](https://api.rocket.rs/v0.5/rocket/fairing/trait.Fairing.html#method.on_ignite "method rocket::fairing::Fairing::on_ignite")
.
---
# rocket::error - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module error](https://api.rocket.rs/v0.5/rocket/error/index.html#)
--------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module error Copy item path
===========================
[Source](https://api.rocket.rs/v0.5/src/rocket/error.rs.html#1-281)
[Search](https://api.rocket.rs/v0.5/rocket/error/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Types representing various errors that can occur in a Rocket application.
Structs[§](https://api.rocket.rs/v0.5/rocket/error/index.html#structs)
-----------------------------------------------------------------------
[Error](https://api.rocket.rs/v0.5/rocket/error/struct.Error.html "struct rocket::error::Error")
An error that occurs during launch.
Enums[§](https://api.rocket.rs/v0.5/rocket/error/index.html#enums)
-------------------------------------------------------------------
[ErrorKind](https://api.rocket.rs/v0.5/rocket/error/enum.ErrorKind.html "enum rocket::error::ErrorKind")
The kind error that occurred.
---
# rocket::config - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module config](https://api.rocket.rs/v0.5/rocket/config/index.html#)
----------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module config Copy item path
============================
[Source](https://api.rocket.rs/v0.5/src/rocket/config/mod.rs.html#1-682)
[Search](https://api.rocket.rs/v0.5/rocket/config/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Server and application configuration.
See the [configuration guide](https://rocket.rs/v0.5/guide/configuration/)
for full details.
### [§](https://api.rocket.rs/v0.5/rocket/config/index.html#extracting-configuration-parameters)
Extracting Configuration Parameters
Rocket exposes the active [`Figment`](https://docs.rs/figment/0.10.19/figment/figment/struct.Figment.html "struct figment::figment::Figment")
via [`Rocket::figment()`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html#method.figment "method rocket::Rocket::figment")
. Any value that implements [`Deserialize`](https://api.rocket.rs/v0.5/rocket/serde/trait.Deserialize.html "trait rocket::serde::Deserialize")
can be extracted from the figment:
use rocket::fairing::AdHoc;
#[derive(serde::Deserialize)]
struct AppConfig {
id: Option,
port: u16,
}
#[rocket::launch]
fn rocket() -> _ {
rocket::build().attach(AdHoc::config::())
}
### [§](https://api.rocket.rs/v0.5/rocket/config/index.html#workers)
Workers
The `workers` parameter sets the number of threads used for parallel task execution; there is no limit to the number of concurrent tasks. Due to a limitation in upstream async executers, unlike other values, the `workers` configuration value cannot be reconfigured or be configured from sources other than those provided by [`Config::figment()`](https://api.rocket.rs/v0.5/rocket/struct.Config.html#method.figment "associated function rocket::Config::figment")
. In other words, only the values set by the `ROCKET_WORKERS` environment variable or in the `workers` property of `Rocket.toml` will be considered - all other `workers` values are ignored.
### [§](https://api.rocket.rs/v0.5/rocket/config/index.html#custom-providers)
Custom Providers
A custom provider can be set via [`rocket::custom()`](https://api.rocket.rs/v0.5/rocket/fn.custom.html "fn rocket::custom")
, which replaces calls to [`rocket::build()`](https://api.rocket.rs/v0.5/rocket/fn.build.html "fn rocket::build")
. The configured provider can be built on top of [`Config::figment()`](https://api.rocket.rs/v0.5/rocket/struct.Config.html#method.figment "associated function rocket::Config::figment")
, [`Config::default()`](https://api.rocket.rs/v0.5/rocket/struct.Config.html#method.default "associated function rocket::Config::default")
, both, or neither. The [Figment](https://docs.rs/figment/0.10.19/figment/index.html "mod figment")
documentation has full details on instantiating existing providers like [`Toml`](https://api.rocket.rs/v0.5/rocket/config/index.html)
and [`Env`](https://docs.rs/figment/0.10.19/figment/providers/env/struct.Env.html "struct figment::providers::env::Env")
as well as creating custom providers for more complex cases.
Configuration values can be overridden at runtime by merging figment’s tuple providers with Rocket’s default provider:
use rocket::data::{Limits, ToByteUnit};
#[launch]
fn rocket() -> _ {
let figment = rocket::Config::figment()
.merge(("port", 1111))
.merge(("limits", Limits::new().limit("json", 2.mebibytes())));
rocket::custom(figment).mount("/", routes![/* .. */])
}
An application that wants to use Rocket’s defaults for [`Config`](https://api.rocket.rs/v0.5/rocket/struct.Config.html "struct rocket::Config")
, but not its configuration sources, while allowing the application to be configured via an `App.toml` file that uses top-level keys as profiles (`.nested()`) and `APP_` environment variables as global overrides (`.global()`), and `APP_PROFILE` to configure the selected profile, can be structured as follows:
use serde::{Serialize, Deserialize};
use figment::{Figment, Profile, providers::{Format, Toml, Serialized, Env}};
use rocket::fairing::AdHoc;
#[derive(Debug, Deserialize, Serialize)]
struct Config {
app_value: usize,
/* and so on.. */
}
impl Default for Config {
fn default() -> Config {
Config { app_value: 3, }
}
}
#[launch]
fn rocket() -> _ {
let figment = Figment::from(rocket::Config::default())
.merge(Serialized::defaults(Config::default()))
.merge(Toml::file("App.toml").nested())
.merge(Env::prefixed("APP_").global())
.select(Profile::from_env_or("APP_PROFILE", "default"));
rocket::custom(figment)
.mount("/", routes![/* .. */])
.attach(AdHoc::config::())
}
Structs[§](https://api.rocket.rs/v0.5/rocket/config/index.html#structs)
------------------------------------------------------------------------
[Config](https://api.rocket.rs/v0.5/rocket/config/struct.Config.html "struct rocket::config::Config")
Rocket server configuration.
[Ident](https://api.rocket.rs/v0.5/rocket/config/struct.Ident.html "struct rocket::config::Ident")
An identifier (or `None`) to send as the `Server` header.
[MutualTls](https://api.rocket.rs/v0.5/rocket/config/struct.MutualTls.html "struct rocket::config::MutualTls")
`mtls`
Mutual TLS configuration.
[SecretKey](https://api.rocket.rs/v0.5/rocket/config/struct.SecretKey.html "struct rocket::config::SecretKey")
`secrets`
A cryptographically secure secret key.
[Shutdown](https://api.rocket.rs/v0.5/rocket/config/struct.Shutdown.html "struct rocket::config::Shutdown")
Graceful shutdown configuration.
[TlsConfig](https://api.rocket.rs/v0.5/rocket/config/struct.TlsConfig.html "struct rocket::config::TlsConfig")
`tls`
TLS configuration: certificate chain, key, and ciphersuites.
Enums[§](https://api.rocket.rs/v0.5/rocket/config/index.html#enums)
--------------------------------------------------------------------
[CipherSuite](https://api.rocket.rs/v0.5/rocket/config/enum.CipherSuite.html "enum rocket::config::CipherSuite")
`tls`
A supported TLS cipher suite.
[LogLevel](https://api.rocket.rs/v0.5/rocket/config/enum.LogLevel.html "enum rocket::config::LogLevel")
Defines the maximum level of log messages to show.
[Sig](https://api.rocket.rs/v0.5/rocket/config/enum.Sig.html "enum rocket::config::Sig")
Unix
A Unix signal for triggering graceful shutdown.
---
# rocket::catcher - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module catcher](https://api.rocket.rs/v0.5/rocket/catcher/index.html#)
------------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module catcher Copy item path
=============================
[Source](https://api.rocket.rs/v0.5/src/rocket/catcher/mod.rs.html#1-7)
[Search](https://api.rocket.rs/v0.5/rocket/catcher/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Types and traits for error catchers and their handlers and return types.
Structs[§](https://api.rocket.rs/v0.5/rocket/catcher/index.html#structs)
-------------------------------------------------------------------------
[Catcher](https://api.rocket.rs/v0.5/rocket/catcher/struct.Catcher.html "struct rocket::catcher::Catcher")
An error catching route.
Traits[§](https://api.rocket.rs/v0.5/rocket/catcher/index.html#traits)
-----------------------------------------------------------------------
[Cloneable](https://api.rocket.rs/v0.5/rocket/catcher/trait.Cloneable.html "trait rocket::catcher::Cloneable")
Helper trait to make a [`Catcher`](https://api.rocket.rs/v0.5/rocket/struct.Catcher.html "struct rocket::Catcher")
’s `Box` `Clone`.
[Handler](https://api.rocket.rs/v0.5/rocket/catcher/trait.Handler.html "trait rocket::catcher::Handler")
Trait implemented by [`Catcher`](https://api.rocket.rs/v0.5/rocket/struct.Catcher.html "struct rocket::Catcher")
error handlers.
Type Aliases[§](https://api.rocket.rs/v0.5/rocket/catcher/index.html#types)
----------------------------------------------------------------------------
[BoxFuture](https://api.rocket.rs/v0.5/rocket/catcher/type.BoxFuture.html "type rocket::catcher::BoxFuture")
Type alias for the return type of a _raw_ [`Catcher`](https://api.rocket.rs/v0.5/rocket/struct.Catcher.html "struct rocket::Catcher")
’s [`Handler`](https://api.rocket.rs/v0.5/rocket/catcher/trait.Handler.html "trait rocket::catcher::Handler")
.
[Result](https://api.rocket.rs/v0.5/rocket/catcher/type.Result.html "type rocket::catcher::Result")
Type alias for the return type of a [`Catcher`](https://api.rocket.rs/v0.5/rocket/struct.Catcher.html "struct rocket::Catcher")
’s [`Handler::handle()`](https://api.rocket.rs/v0.5/rocket/catcher/trait.Handler.html#tymethod.handle "method rocket::catcher::Handler::handle")
.
---
# rocket::data - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module data](https://api.rocket.rs/v0.5/rocket/data/index.html#)
------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module data Copy item path
==========================
[Source](https://api.rocket.rs/v0.5/src/rocket/data/mod.rs.html#1-19)
[Search](https://api.rocket.rs/v0.5/rocket/data/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Types and traits for handling incoming body data.
Structs[§](https://api.rocket.rs/v0.5/rocket/data/index.html#structs)
----------------------------------------------------------------------
[ByteUnit](https://api.rocket.rs/v0.5/rocket/data/struct.ByteUnit.html "struct rocket::data::ByteUnit")
A unit of bytes with saturating `const` constructors and arithmetic.
[Capped](https://api.rocket.rs/v0.5/rocket/data/struct.Capped.html "struct rocket::data::Capped")
Encapsulates a value capped to a data limit.
[Data](https://api.rocket.rs/v0.5/rocket/data/struct.Data.html "struct rocket::data::Data")
Type representing the body data of a request.
[DataStream](https://api.rocket.rs/v0.5/rocket/data/struct.DataStream.html "struct rocket::data::DataStream")
Raw data stream of a request body.
[IoStream](https://api.rocket.rs/v0.5/rocket/data/struct.IoStream.html "struct rocket::data::IoStream")
A bidirectional, raw stream to the client.
[Limits](https://api.rocket.rs/v0.5/rocket/data/struct.Limits.html "struct rocket::data::Limits")
Mapping from (hierarchical) data types to size limits.
[N](https://api.rocket.rs/v0.5/rocket/data/struct.N.html "struct rocket::data::N")
Number of bytes read/written and whether that consisted of the entire stream.
Traits[§](https://api.rocket.rs/v0.5/rocket/data/index.html#traits)
--------------------------------------------------------------------
[FromData](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
Trait implemented by data guards to derive a value from request body data.
[IoHandler](https://api.rocket.rs/v0.5/rocket/data/trait.IoHandler.html "trait rocket::data::IoHandler")
An upgraded connection I/O handler.
[ToByteUnit](https://api.rocket.rs/v0.5/rocket/data/trait.ToByteUnit.html "trait rocket::data::ToByteUnit")
Extension trait for conversion from integer types to [`ByteUnit`](https://api.rocket.rs/v0.5/rocket/data/struct.ByteUnit.html "struct rocket::data::ByteUnit")
.
Type Aliases[§](https://api.rocket.rs/v0.5/rocket/data/index.html#types)
-------------------------------------------------------------------------
[Outcome](https://api.rocket.rs/v0.5/rocket/data/type.Outcome.html "type rocket::data::Outcome")
Type alias for the `Outcome` of [`FromData`](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
.
---
# rocket::local - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module local](https://api.rocket.rs/v0.5/rocket/local/index.html#)
--------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module local Copy item path
===========================
[Source](https://api.rocket.rs/v0.5/src/rocket/local/mod.rs.html#1-187)
[Search](https://api.rocket.rs/v0.5/rocket/local/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Structures for local dispatching of requests, primarily for testing.
This module allows for simple request dispatching against a local, non-networked instance of Rocket. The primary use of this module is to unit and integration test Rocket applications by crafting requests, dispatching them, and verifying the response.
[§](https://api.rocket.rs/v0.5/rocket/local/index.html#async-vs-blocking)
Async. vs. Blocking
---------------------------------------------------------------------------------------------
This module contains two variants, in its two submodules, of the same local API: [`asynchronous`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/index.html "mod rocket::local::asynchronous")
, and [`blocking`](https://api.rocket.rs/v0.5/rocket/local/blocking/index.html "mod rocket::local::blocking")
. As their names imply, the `asynchronous` API is `async`, returning a `Future` for operations that would otherwise block, while `blocking` blocks for the same operations.
Unless your request handling requires concurrency to make progress, or you’re making use of a `Client` in an environment that necessitates or would benefit from concurrency, you should use the `blocking` set of APIs due their ease-of-use. If your request handling _does_ require concurrency to make progress, for instance by having one handler `await` a response generated from a request to another handler, use the `asynchronous` set of APIs.
Both APIs include a `Client` structure that is used to create `LocalRequest` structures that can be dispatched against a given [`Rocket`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html "struct rocket::Rocket")
instance to yield a `LocalResponse` structure. The APIs are identical except in that the `asynchronous` APIs return `Future`s for otherwise blocking operations.
[§](https://api.rocket.rs/v0.5/rocket/local/index.html#unitintegration-testing)
Unit/Integration Testing
--------------------------------------------------------------------------------------------------------
This module is primarily intended to be used to test a Rocket application by constructing requests via `Client`, dispatching them, and validating the resulting response. As a complete example, consider the following “Hello, world!” application, with testing.
#[macro_use] extern crate rocket;
#[get("/")]
fn hello() -> &'static str {
"Hello, world!"
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![hello])
}
#[cfg(test)]
mod test {
// Using the preferred `blocking` API.
#[test]
fn test_hello_world_blocking() {
use rocket::local::blocking::Client;
// Construct a client to use for dispatching requests.
let client = Client::tracked(super::rocket())
.expect("valid `Rocket`");
// Dispatch a request to 'GET /' and validate the response.
let response = client.get("/").dispatch();
assert_eq!(response.into_string().unwrap(), "Hello, world!");
}
// Using the `asynchronous` API.
#[rocket::async_test]
async fn test_hello_world_async() {
use rocket::local::asynchronous::Client;
// Construct a client to use for dispatching requests.
let client = Client::tracked(super::rocket()).await
.expect("valid `Rocket`");
// Dispatch a request to 'GET /' and validate the response.
let response = client.get("/").dispatch().await;
assert_eq!(response.into_string().await.unwrap(), "Hello, world!");
}
}
For more details on testing, see the [testing guide](https://rocket.rs/v0.5/guide/testing/)
.
[§](https://api.rocket.rs/v0.5/rocket/local/index.html#client)
`Client`
-----------------------------------------------------------------------
A `Client`, either [`blocking::Client`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.Client.html "struct rocket::local::blocking::Client")
or [`asynchronous::Client`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html "struct rocket::local::asynchronous::Client")
, referred to as simply [`Client`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html "struct rocket::local::asynchronous::Client")
and [`async` `Client`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html "struct rocket::local::asynchronous::Client")
, respectively, constructs requests for local dispatching.
**Usage**
A `Client` is constructed via the [`tracked()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.Client.html#method.tracked "associated function rocket::local::blocking::Client::tracked")
([`async` `tracked()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html#method.tracked "associated function rocket::local::asynchronous::Client::tracked")
) or [`untracked()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.Client.html#method.untracked "associated function rocket::local::blocking::Client::untracked")
([`async` `untracked()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html#method.untracked "associated function rocket::local::asynchronous::Client::untracked")
) methods from an already constructed `Rocket` instance. Once a value of `Client` has been constructed, [`get()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.Client.html#method.get "method rocket::local::blocking::Client::get")
, [`put()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.Client.html#method.put "method rocket::local::blocking::Client::put")
, [`post()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.Client.html#method.post "method rocket::local::blocking::Client::post")
, and so on ([`async` `get()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html#method.get "method rocket::local::asynchronous::Client::get")
, [`async` `put()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html#method.put "method rocket::local::asynchronous::Client::put")
, [`async` `post()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html#method.post "method rocket::local::asynchronous::Client::post")
) can be called to create a [`LocalRequest`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalRequest.html "struct rocket::local::blocking::LocalRequest")
([`async` `LocalRequest`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalRequest.html "struct rocket::local::asynchronous::LocalRequest")
) for dispatching.
**Cookie Tracking**
A `Client` constructed using `tracked()` propagates cookie changes made by responses to previously dispatched requests. In other words, if a previously dispatched request resulted in a response that adds a cookie, any future requests will contain that cookie. Similarly, cookies removed by a response won’t be propagated further.
This is typically the desired mode of operation for a `Client` as it removes the burden of manually tracking cookies. Under some circumstances, however, disabling this tracking may be desired. In these cases, use the `untracked()` constructor to create a `Client` that _will not_ track cookies.
**Example**
For a usage example, see [`Client`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html "struct rocket::local::asynchronous::Client")
or [`async` `Client`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.Client.html "struct rocket::local::asynchronous::Client")
.
[§](https://api.rocket.rs/v0.5/rocket/local/index.html#localrequest)
`LocalRequest`
-----------------------------------------------------------------------------------
A [`LocalRequest`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalRequest.html "struct rocket::local::blocking::LocalRequest")
([`async` `LocalRequest`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalRequest.html "struct rocket::local::asynchronous::LocalRequest")
) is constructed via a `Client`. Once obtained, headers, cookies, including private cookies, the remote IP address, and the request body can all be set via methods on the `LocalRequest` structure.
**Dispatching**
A `LocalRequest` is dispatched by calling [`dispatch()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalRequest.html#method.dispatch "method rocket::local::blocking::LocalRequest::dispatch")
([`async` `dispatch()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalRequest.html#method.dispatch "method rocket::local::asynchronous::LocalRequest::dispatch")
). The `LocalRequest` is consumed and a [`LocalResponse`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalResponse.html "struct rocket::local::blocking::LocalResponse")
([`async` `LocalResponse`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalResponse.html "struct rocket::local::asynchronous::LocalResponse")
) is returned.
Note that `LocalRequest` implements [`Clone`](https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html "trait core::clone::Clone")
. As such, if the same request needs to be dispatched multiple times, the request can first be cloned and then dispatched: `request.clone().dispatch()`.
**Example**
For a usage example, see [`LocalRequest`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalRequest.html "struct rocket::local::blocking::LocalRequest")
or [`async` `LocalRequest`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalRequest.html "struct rocket::local::asynchronous::LocalRequest")
.
[§](https://api.rocket.rs/v0.5/rocket/local/index.html#localresponse)
`LocalResponse`
-------------------------------------------------------------------------------------
The result of `dispatch()`ing a `LocalRequest` is a [`LocalResponse`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalResponse.html "struct rocket::local::blocking::LocalResponse")
([`async` `LocalResponse`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalResponse.html "struct rocket::local::asynchronous::LocalResponse")
). A `LocalResponse` can be queried for response metadata, including the HTTP status, headers, and cookies, via its getter methods. Additionally, the body of the response can be read into a string ([`into_string()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalResponse.html#method.into_string "method rocket::local::blocking::LocalResponse::into_string")
or [`async` `into_string()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalResponse.html#method.into_string "method rocket::local::asynchronous::LocalResponse::into_string")
) or a vector ([`into_bytes()`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalResponse.html#method.into_bytes "method rocket::local::blocking::LocalResponse::into_bytes")
or [`async` `into_bytes()`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalResponse.html#method.into_bytes "method rocket::local::asynchronous::LocalResponse::into_bytes")
).
The response body must also be read directly using standard I/O mechanisms: the `blocking` `LocalResponse` implements `Read` while the `async` `LocalResponse` implements `AsyncRead`.
For a usage example, see [`LocalResponse`](https://api.rocket.rs/v0.5/rocket/local/blocking/struct.LocalResponse.html "struct rocket::local::blocking::LocalResponse")
or [`async` `LocalResponse`](https://api.rocket.rs/v0.5/rocket/local/asynchronous/struct.LocalResponse.html "struct rocket::local::asynchronous::LocalResponse")
.
Modules[§](https://api.rocket.rs/v0.5/rocket/local/index.html#modules)
-----------------------------------------------------------------------
[asynchronous](https://api.rocket.rs/v0.5/rocket/local/asynchronous/index.html "mod rocket::local::asynchronous")
Asynchronous local dispatching of requests.
[blocking](https://api.rocket.rs/v0.5/rocket/local/blocking/index.html "mod rocket::local::blocking")
Blocking local dispatching of requests.
---
# rocket::fs - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module fs](https://api.rocket.rs/v0.5/rocket/fs/index.html#)
--------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module fs Copy item path
========================
[Source](https://api.rocket.rs/v0.5/src/rocket/fs/mod.rs.html#1-12)
[Search](https://api.rocket.rs/v0.5/rocket/fs/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
File serving, file accepting, and file metadata types.
Macros[§](https://api.rocket.rs/v0.5/rocket/fs/index.html#macros)
------------------------------------------------------------------
[relative](https://api.rocket.rs/v0.5/rocket/fs/macro.relative.html "macro rocket::fs::relative")
`nightly`
Generates a crate-relative version of a path.
Structs[§](https://api.rocket.rs/v0.5/rocket/fs/index.html#structs)
--------------------------------------------------------------------
[FileName](https://api.rocket.rs/v0.5/rocket/fs/struct.FileName.html "struct rocket::fs::FileName")
A file name in a [`TempFile`](https://api.rocket.rs/v0.5/rocket/fs/enum.TempFile.html "enum rocket::fs::TempFile")
or multipart [`DataField`](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")
.
[FileServer](https://api.rocket.rs/v0.5/rocket/fs/struct.FileServer.html "struct rocket::fs::FileServer")
Custom handler for serving static files.
[NamedFile](https://api.rocket.rs/v0.5/rocket/fs/struct.NamedFile.html "struct rocket::fs::NamedFile")
A [`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html "trait rocket::response::Responder")
that sends file data with a Content-Type based on its file extension.
[Options](https://api.rocket.rs/v0.5/rocket/fs/struct.Options.html "struct rocket::fs::Options")
A bitset representing configurable options for [`FileServer`](https://api.rocket.rs/v0.5/rocket/fs/struct.FileServer.html "struct rocket::fs::FileServer")
.
Enums[§](https://api.rocket.rs/v0.5/rocket/fs/index.html#enums)
----------------------------------------------------------------
[TempFile](https://api.rocket.rs/v0.5/rocket/fs/enum.TempFile.html "enum rocket::fs::TempFile")
A data and form guard that streams data into a temporary file.
---
# rocket::outcome - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module outcome](https://api.rocket.rs/v0.5/rocket/outcome/index.html#)
------------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module outcome Copy item path
=============================
[Source](https://api.rocket.rs/v0.5/src/rocket/outcome.rs.html#1-867)
[Search](https://api.rocket.rs/v0.5/rocket/outcome/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Success, error, and forward handling.
The `Outcome` type is similar to the standard library’s `Result` type. It is an enum with three variants, each containing a value: `Success(S)`, which represents a successful outcome, `Error(E)`, which represents an erroring outcome, and `Forward(F)`, which represents neither a success or error, but instead, indicates that processing could not be handled and should instead be _forwarded_ to whatever can handle the processing next.
The `Outcome` type is the return type of many of the core Rocket traits, including [`FromRequest`](https://api.rocket.rs/v0.5/rocket/request/trait.FromRequest.html "trait rocket::request::FromRequest")
, [`FromData`](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
[`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html "trait rocket::response::Responder")
. It is also the return type of request handlers via the [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html "struct rocket::Response")
type.
[§](https://api.rocket.rs/v0.5/rocket/outcome/index.html#success)
Success
-------------------------------------------------------------------------
A successful `Outcome`, `Success(S)`, is returned from functions that complete successfully. The meaning of a `Success` outcome depends on the context. For instance, the `Outcome` of the `from_data` method of the [`FromData`](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
trait will be matched against the type expected by the user. For example, consider the following handler:
#[post("/", data = "")]
fn hello(my_val: S) { /* ... */ }
The [`FromData`](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
implementation for the type `S` returns an `Outcome` with a `Success(S)`. If `from_data` returns a `Success`, the `Success` value will be unwrapped and the value will be used as the value of `my_val`.
[§](https://api.rocket.rs/v0.5/rocket/outcome/index.html#error)
Error
---------------------------------------------------------------------
An error `Outcome`, `Error(E)`, is returned when a function fails with some error and no processing can or should continue as a result. The meaning of an error depends on the context.
In Rocket, an `Error` generally means that a request is taken out of normal processing. The request is then given to the catcher corresponding to some status code. Users can catch errors by requesting a type of `Result` or `Option` in request handlers. For example, if a user’s handler looks like:
#[post("/", data = "")]
fn hello(my_val: Result) { /* ... */ }
The [`FromData`](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
implementation for the type `S` returns an `Outcome` with a `Success(S)` and `Error(E)`. If `from_data` returns an `Error`, the `Error` value will be unwrapped and the value will be used as the `Err` value of `my_val` while a `Success` will be unwrapped and used the `Ok` value.
[§](https://api.rocket.rs/v0.5/rocket/outcome/index.html#forward)
Forward
-------------------------------------------------------------------------
A forward `Outcome`, `Forward(F)`, is returned when a function wants to indicate that the requested processing should be _forwarded_ to the next available processor. Again, the exact meaning depends on the context.
In Rocket, a `Forward` generally means that a request is forwarded to the next available request handler. For example, consider the following request handler:
#[post("/", data = "")]
fn hello(my_val: S) { /* ... */ }
The [`FromData`](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
implementation for the type `S` returns an `Outcome` with a `Success(S)`, `Error(E)`, and `Forward(F)`. If the `Outcome` is a `Forward`, the `hello` handler isn’t called. Instead, the incoming request is forwarded, or passed on to, the next matching route, if any. Ultimately, if there are no non-forwarding routes, forwarded requests are handled by the 404 catcher. Similar to `Error`s, users can catch `Forward`s by requesting a type of `Option`. If an `Outcome` is a `Forward`, the `Option` will be `None`.
Macros[§](https://api.rocket.rs/v0.5/rocket/outcome/index.html#macros)
-----------------------------------------------------------------------
[try\_outcome](https://api.rocket.rs/v0.5/rocket/outcome/macro.try_outcome.html "macro rocket::outcome::try_outcome")
`nightly`
Unwraps a [`Success`](https://api.rocket.rs/v0.5/rocket/outcome/enum.Outcome.html#variant.Success "variant rocket::outcome::Outcome::Success")
or propagates a `Forward` or `Error` by returning early.
Enums[§](https://api.rocket.rs/v0.5/rocket/outcome/index.html#enums)
---------------------------------------------------------------------
[Outcome](https://api.rocket.rs/v0.5/rocket/outcome/enum.Outcome.html "enum rocket::outcome::Outcome")
An enum representing success (`Success`), error (`Error`), or forwarding (`Forward`).
Traits[§](https://api.rocket.rs/v0.5/rocket/outcome/index.html#traits)
-----------------------------------------------------------------------
[IntoOutcome](https://api.rocket.rs/v0.5/rocket/outcome/trait.IntoOutcome.html "trait rocket::outcome::IntoOutcome")
Conversion trait from some type into an Outcome type.
---
# rocket::form - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module form](https://api.rocket.rs/v0.5/rocket/form/index.html#)
------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module form Copy item path
==========================
[Source](https://api.rocket.rs/v0.5/src/rocket/form/mod.rs.html#1-406)
[Search](https://api.rocket.rs/v0.5/rocket/form/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Parsing and validation of HTTP forms and fields.
See the [forms guide](https://rocket.rs/v0.5/guide/requests#forms)
for general form support documentation.
[§](https://api.rocket.rs/v0.5/rocket/form/index.html#field-wire-format)
Field Wire Format
------------------------------------------------------------------------------------------
Rocket’s field wire format is a flexible, non-self-descriptive, text-based encoding of arbitrarily nested structure keys and their corresponding values. The general grammar is:
field := name ('=' value)?
name := key*
key := indices
| '[' indices ']'
| '.' indices
indices := index (':' index)*
index := STRING except ':', ']'
value := STRING
Each field name consists of any number of `key`s and at most one `value`. Keys are delimited by `[` or `.`. A `key` consists of indices delimited by `:`.\
\
The meaning of a key or index is type-dependent, hence the format is non-self-descriptive. _Any_ structure can be described by this format. The delimiters `.`, `[`, `:`, and `]` have no semantic meaning.\
\
Some examples of valid fields are:\
\
* `=`\
* `key=value`\
* `key[]=value`\
* `.0=value`\
* `[0]=value`\
* `people[].name=Bob`\
* `bob.cousin.names[]=Bob`\
* `map[k:1]=Bob`\
* `people[bob]nickname=Stan`\
\
See [`FromForm`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")\
for full details on push-parsing and complete examples, and [`Form`](https://api.rocket.rs/v0.5/rocket/form/struct.Form.html "struct rocket::form::Form")\
for how to accept forms in a request handler.\
\
Modules[§](https://api.rocket.rs/v0.5/rocket/form/index.html#modules)\
\
----------------------------------------------------------------------\
\
[error](https://api.rocket.rs/v0.5/rocket/form/error/index.html "mod rocket::form::error")\
\
Form error types.\
\
[name](https://api.rocket.rs/v0.5/rocket/form/name/index.html "mod rocket::form::name")\
\
Types for field names, name keys, and key indices.\
\
[validate](https://api.rocket.rs/v0.5/rocket/form/validate/index.html "mod rocket::form::validate")\
\
Form field validation routines.\
\
Structs[§](https://api.rocket.rs/v0.5/rocket/form/index.html#structs)\
\
----------------------------------------------------------------------\
\
[Context](https://api.rocket.rs/v0.5/rocket/form/struct.Context.html "struct rocket::form::Context")\
\
A form context containing received fields, values, and encountered errors.\
\
[Contextual](https://api.rocket.rs/v0.5/rocket/form/struct.Contextual.html "struct rocket::form::Contextual")\
\
An infallible form guard that records form fields and errors during parsing.\
\
[DataField](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")\
\
A multipart form field with an underlying data stream.\
\
[Error](https://api.rocket.rs/v0.5/rocket/form/struct.Error.html "struct rocket::form::Error")\
\
A form error, potentially tied to a specific form field.\
\
[Errors](https://api.rocket.rs/v0.5/rocket/form/struct.Errors.html "struct rocket::form::Errors")\
\
A collection of [`Error`](https://api.rocket.rs/v0.5/rocket/form/struct.Error.html "struct rocket::form::Error")\
s.\
\
[Form](https://api.rocket.rs/v0.5/rocket/form/struct.Form.html "struct rocket::form::Form")\
\
A data guard for [`FromForm`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")\
types.\
\
[Lenient](https://api.rocket.rs/v0.5/rocket/form/struct.Lenient.html "struct rocket::form::Lenient")\
\
A form guard for parsing form types leniently.\
\
[Options](https://api.rocket.rs/v0.5/rocket/form/struct.Options.html "struct rocket::form::Options")\
\
Form guard options.\
\
[Strict](https://api.rocket.rs/v0.5/rocket/form/struct.Strict.html "struct rocket::form::Strict")\
\
A form guard for parsing form types strictly.\
\
[ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
\
A form field with a string value.\
\
Traits[§](https://api.rocket.rs/v0.5/rocket/form/index.html#traits)\
\
--------------------------------------------------------------------\
\
[FromForm](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")\
\
Trait implemented by form guards: types parseable from HTTP forms.\
\
[FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
\
Implied form guard ([`FromForm`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")\
) for parsing a single form field.\
\
Type Aliases[§](https://api.rocket.rs/v0.5/rocket/form/index.html#types)\
\
-------------------------------------------------------------------------\
\
[Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
\
Type alias for `Result` with an error type of [`Errors`](https://api.rocket.rs/v0.5/rocket/form/struct.Errors.html "struct rocket::form::Errors")\
.
---
# Phase in rocket - Rust
[Phase](https://api.rocket.rs/v0.5/rocket/trait.Phase#)
--------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Trait Phase Copy item path
==========================
[Source](https://api.rocket.rs/v0.5/src/rocket/phase.rs.html#26-29)
pub trait Phase: Sealed { }
Expand description
A marker trait for Rocket’s launch phases.
This treat is implemented by the three phase marker types: [`Build`](https://api.rocket.rs/v0.5/rocket/enum.Build.html "enum rocket::Build")
, [`Ignite`](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
, and [`Orbit`](https://api.rocket.rs/v0.5/rocket/enum.Orbit.html "enum rocket::Orbit")
, representing the three phases to launch an instance of [`Rocket`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html "struct rocket::Rocket")
. This trait is _sealed_ and cannot be implemented outside of Rocket.
For a description of the three phases, see [`Rocket`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html#phases "struct rocket::Rocket")
.
Implementors[§](https://api.rocket.rs/v0.5/rocket/trait.Phase#implementors)
----------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/phase.rs.html#75-117)
[§](https://api.rocket.rs/v0.5/rocket/trait.Phase#impl-Phase-for-Build)
### impl [Phase](https://api.rocket.rs/v0.5/rocket/trait.Phase.html "trait rocket::Phase")
for [Build](https://api.rocket.rs/v0.5/rocket/enum.Build.html "enum rocket::Build")
[Source](https://api.rocket.rs/v0.5/src/rocket/phase.rs.html#75-117)
[§](https://api.rocket.rs/v0.5/rocket/trait.Phase#impl-Phase-for-Ignite)
### impl [Phase](https://api.rocket.rs/v0.5/rocket/trait.Phase.html "trait rocket::Phase")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
[Source](https://api.rocket.rs/v0.5/src/rocket/phase.rs.html#75-117)
[§](https://api.rocket.rs/v0.5/rocket/trait.Phase#impl-Phase-for-Orbit)
### impl [Phase](https://api.rocket.rs/v0.5/rocket/trait.Phase.html "trait rocket::Phase")
for [Orbit](https://api.rocket.rs/v0.5/rocket/enum.Orbit.html "enum rocket::Orbit")
---
# rocket::request - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module request](https://api.rocket.rs/v0.5/rocket/request/index.html#)
------------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module request Copy item path
=============================
[Source](https://api.rocket.rs/v0.5/src/rocket/request/mod.rs.html#1-113)
[Search](https://api.rocket.rs/v0.5/rocket/request/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Types and traits for request parsing and handling.
Macros[§](https://api.rocket.rs/v0.5/rocket/request/index.html#macros)
-----------------------------------------------------------------------
[local\_cache](https://api.rocket.rs/v0.5/rocket/request/macro.local_cache.html "macro rocket::request::local_cache")
`nightly`
Store and immediately retrieve a vector-like value `$v` (`String` or `Vec`) in `$request`’s local cache using a locally generated anonymous type to avoid type conflicts.
[local\_cache\_once](https://api.rocket.rs/v0.5/rocket/request/macro.local_cache_once.html "macro rocket::request::local_cache_once")
`nightly`
Store and immediately retrieve a value `$v` in `$request`’s local cache using a locally generated anonymous type to avoid type conflicts.
Structs[§](https://api.rocket.rs/v0.5/rocket/request/index.html#structs)
-------------------------------------------------------------------------
[Request](https://api.rocket.rs/v0.5/rocket/request/struct.Request.html "struct rocket::request::Request")
The type of an incoming web request.
Traits[§](https://api.rocket.rs/v0.5/rocket/request/index.html#traits)
-----------------------------------------------------------------------
[FromParam](https://api.rocket.rs/v0.5/rocket/request/trait.FromParam.html "trait rocket::request::FromParam")
Trait to convert a dynamic path segment string to a concrete value.
[FromRequest](https://api.rocket.rs/v0.5/rocket/request/trait.FromRequest.html "trait rocket::request::FromRequest")
Trait implemented by request guards to derive a value from incoming requests.
[FromSegments](https://api.rocket.rs/v0.5/rocket/request/trait.FromSegments.html "trait rocket::request::FromSegments")
Trait to convert _many_ dynamic path segment strings to a concrete value.
Type Aliases[§](https://api.rocket.rs/v0.5/rocket/request/index.html#types)
----------------------------------------------------------------------------
[FlashMessage](https://api.rocket.rs/v0.5/rocket/request/type.FlashMessage.html "type rocket::request::FlashMessage")
Type alias to retrieve [`Flash`](https://api.rocket.rs/v0.5/rocket/response/struct.Flash.html "struct rocket::response::Flash")
messages from a request.
[Outcome](https://api.rocket.rs/v0.5/rocket/request/type.Outcome.html "type rocket::request::Outcome")
Type alias for the `Outcome` of a `FromRequest` conversion.
---
# Ignite in rocket - Rust
[Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite#)
---------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Enum Ignite Copy item path
==========================
[Source](https://api.rocket.rs/v0.5/src/rocket/phase.rs.html#75-117)
pub enum Ignite {}
Expand description
The second launch [`Phase`](https://api.rocket.rs/v0.5/rocket/trait.Phase.html "trait rocket::Phase")
: post-build but pre-orbit. See [Rocket#ignite](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html#ignite "struct rocket::Rocket")
for details.
An instance of `Rocket` in this phase is typed as [`Rocket`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html "struct rocket::Rocket")
and represents a fully built and finalized application server ready for launch into orbit. See [`Rocket`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html#ignite "struct rocket::Rocket")
for full details.
Trait Implementations[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#trait-implementations)
----------------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/phase.rs.html#75-117)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Phase-for-Ignite)
### impl [Phase](https://api.rocket.rs/v0.5/rocket/trait.Phase.html "trait rocket::Phase")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
Auto Trait Implementations[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#synthetic-implementations)
-------------------------------------------------------------------------------------------------------
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Freeze-for-Ignite)
### impl [Freeze](https://doc.rust-lang.org/nightly/core/marker/trait.Freeze.html "trait core::marker::Freeze")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-RefUnwindSafe-for-Ignite)
### impl [RefUnwindSafe](https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html "trait core::panic::unwind_safe::RefUnwindSafe")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Send-for-Ignite)
### impl [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Sync-for-Ignite)
### impl [Sync](https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html "trait core::marker::Sync")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Unpin-for-Ignite)
### impl [Unpin](https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html "trait core::marker::Unpin")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-UnwindSafe-for-Ignite)
### impl [UnwindSafe](https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html "trait core::panic::unwind_safe::UnwindSafe")
for [Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
Blanket Implementations[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#blanket-implementations)
--------------------------------------------------------------------------------------------------
[Source](https://doc.rust-lang.org/nightly/src/core/any.rs.html#138)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Any-for-T)
### impl [Any](https://doc.rust-lang.org/nightly/core/any/trait.Any.html "trait core::any::Any")
for T
where T: 'static + ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://doc.rust-lang.org/nightly/src/core/any.rs.html#139)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.type_id)
#### fn [type\_id](https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id)
(&self) -> [TypeId](https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html "struct core::any::TypeId")
Gets the `TypeId` of `self`. [Read more](https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id)
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#300)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-AsTaggedExplicit%3C'a%3E-for-T)
### impl<'a, T> [AsTaggedExplicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedExplicit.html "trait rocket::mtls::oid::asn1_rs::AsTaggedExplicit")
<'a> for T
where T: 'a,
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#295)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.explicit)
#### fn [explicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedExplicit.html#method.explicit)
(self, class: [Class](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Class.html "enum rocket::mtls::oid::asn1_rs::Class")
, tag: [u32](https://doc.rust-lang.org/nightly/std/primitive.u32.html)
) -> [TaggedParser](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/struct.TaggedParser.html "struct rocket::mtls::oid::asn1_rs::TaggedParser")
<'a, [Explicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Explicit.html "enum rocket::mtls::oid::asn1_rs::Explicit")
, Self>
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#323)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-AsTaggedImplicit%3C'a%3E-for-T)
### impl<'a, T> [AsTaggedImplicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedImplicit.html "trait rocket::mtls::oid::asn1_rs::AsTaggedImplicit")
<'a> for T
where T: 'a,
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#313-318)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.implicit)
#### fn [implicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedImplicit.html#method.implicit)
( self, class: [Class](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Class.html "enum rocket::mtls::oid::asn1_rs::Class")
, constructed: [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
, tag: [u32](https://doc.rust-lang.org/nightly/std/primitive.u32.html)
, ) -> [TaggedParser](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/struct.TaggedParser.html "struct rocket::mtls::oid::asn1_rs::TaggedParser")
<'a, [Implicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Implicit.html "enum rocket::mtls::oid::asn1_rs::Implicit")
, Self>
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#212)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Borrow%3CT%3E-for-T)
### impl [Borrow](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html "trait core::borrow::Borrow")
for T
where T: ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#214)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.borrow)
#### fn [borrow](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow)
(&self) -> [&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
Immutably borrows from an owned value. [Read more](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow)
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-BorrowMut%3CT%3E-for-T)
### impl [BorrowMut](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html "trait core::borrow::BorrowMut")
for T
where T: ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#222)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.borrow_mut)
#### fn [borrow\_mut](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut)
(&mut self) -> [&mut T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
Mutably borrows from an owned value. [Read more](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut)
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#785)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-From%3CT%3E-for-T)
### impl [From](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::From")
for T
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#788)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.from)
#### fn [from](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html#tymethod.from)
(t: T) -> T
Returns the argument unchanged.
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#325)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Instrument-for-T)
### impl [Instrument](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html "trait tracing::instrument::Instrument")
for T
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#86)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.instrument)
#### fn [instrument](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.instrument)
(self, span: [Span](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html "struct tracing::span::Span")
) -> [Instrumented](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.Instrumented.html "struct tracing::instrument::Instrumented")
[ⓘ](https://api.rocket.rs/v0.5/rocket/enum.Ignite#)
Instruments this type with the provided [`Span`](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html "struct tracing::span::Span")
, returning an `Instrumented` wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.instrument)
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#128)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.in_current_span)
#### fn [in\_current\_span](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.in_current_span)
(self) -> [Instrumented](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.Instrumented.html "struct tracing::instrument::Instrumented")
[ⓘ](https://api.rocket.rs/v0.5/rocket/enum.Ignite#)
Instruments this type with the [current](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html#method.current "associated function tracing::span::Span::current")
[`Span`](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html "struct tracing::span::Span")
, returning an `Instrumented` wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.in_current_span)
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#767-769)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Into%3CU%3E-for-T)
### impl [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
for T
where U: [From](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::From")
,
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#777)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.into)
#### fn [into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html#tymethod.into)
(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::From") for U` chooses to do.
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-IntoCollection%3CT%3E-for-T)
### impl [IntoCollection](https://api.rocket.rs/v0.5/rocket/http/ext/trait.IntoCollection.html "trait rocket::http::ext::IntoCollection")
for T
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.into_collection)
#### fn [into\_collection](https://api.rocket.rs/v0.5/rocket/http/ext/trait.IntoCollection.html#tymethod.into_collection)
(self) -> [SmallVec](https://docs.rs/smallvec/1.15.1/smallvec/struct.SmallVec.html "struct smallvec::SmallVec")
where A: [Array](https://docs.rs/smallvec/1.15.1/smallvec/trait.Array.html "trait smallvec::Array")
- ,
Converts `self` into a collection.
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.mapped)
#### fn [mapped](https://api.rocket.rs/v0.5/rocket/http/ext/trait.IntoCollection.html#tymethod.mapped)
(self, f: F) -> [SmallVec](https://docs.rs/smallvec/1.15.1/smallvec/struct.SmallVec.html "struct smallvec::SmallVec")
where F: [FnMut](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/ops/trait.FnMut.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::ops::FnMut")
(T) -> U, A: [Array](https://docs.rs/smallvec/1.15.1/smallvec/trait.Array.html "trait smallvec::Array")
- ,
[Source](https://docs.rs/either/1/src/either/into_either.rs.html#64)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-IntoEither-for-T)
### impl [IntoEither](https://docs.rs/either/1/either/into_either/trait.IntoEither.html "trait either::into_either::IntoEither")
for T
[Source](https://docs.rs/either/1/src/either/into_either.rs.html#29)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.into_either)
#### fn [into\_either](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either)
(self, into\_left: [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
) -> [Either](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
[ⓘ](https://api.rocket.rs/v0.5/rocket/enum.Ignite#)
Converts `self` into a [`Left`](https://docs.rs/either/1/either/enum.Either.html#variant.Left "variant either::Either::Left")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
if `into_left` is `true`. Converts `self` into a [`Right`](https://docs.rs/either/1/either/enum.Either.html#variant.Right "variant either::Either::Right")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
otherwise. [Read more](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either)
[Source](https://docs.rs/either/1/src/either/into_either.rs.html#55-57)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.into_either_with)
#### fn [into\_either\_with](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either_with)
(self, into\_left: F) -> [Either](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
[ⓘ](https://api.rocket.rs/v0.5/rocket/enum.Ignite#)
where F: [FnOnce](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/ops/trait.FnOnce.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::ops::FnOnce")
(&Self) -> [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
,
Converts `self` into a [`Left`](https://docs.rs/either/1/either/enum.Either.html#variant.Left "variant either::Either::Left")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
if `into_left(&self)` returns `true`. Converts `self` into a [`Right`](https://docs.rs/either/1/either/enum.Either.html#variant.Right "variant either::Either::Right")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
otherwise. [Read more](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either_with)
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#134)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Paint-for-T)
### impl [Paint](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html "trait yansi::paint::Paint")
for T
where T: ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.fg)
#### fn [fg](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.fg)
(&self, value: [Color](https://docs.rs/yansi/1.0.1/yansi/color/enum.Color.html "enum yansi::color::Color")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns a styled value derived from `self` with the foreground set to `value`.
This method should be used rarely. Instead, prefer to use color-specific builder methods like [`red()`](self::red())
and [`green()`](self::green())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example)
Example
Set foreground color to white using `fg()`:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using [`white()`](self::white())
.
use yansi::Paint;
painted.white();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.primary)
#### fn [primary](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.primary)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Primary`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-1)
Example
println!("{}", value.primary());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.fixed)
#### fn [fixed](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.fixed)
(&self, color: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Fixed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-2)
Example
println!("{}", value.fixed(color));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.rgb)
#### fn [rgb](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.rgb)
(&self, r: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, g: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, b: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Rgb`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-3)
Example
println!("{}", value.rgb(r, g, b));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.black)
#### fn [black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Black`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-4)
Example
println!("{}", value.black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.red)
#### fn [red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Red`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-5)
Example
println!("{}", value.red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.green)
#### fn [green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Green`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-6)
Example
println!("{}", value.green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.yellow)
#### fn [yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Yellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-7)
Example
println!("{}", value.yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.blue)
#### fn [blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Blue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-8)
Example
println!("{}", value.blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.magenta)
#### fn [magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Magenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-9)
Example
println!("{}", value.magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.cyan)
#### fn [cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Cyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-10)
Example
println!("{}", value.cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.white)
#### fn [white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: White`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-11)
Example
println!("{}", value.white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_black)
#### fn [bright\_black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightBlack`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-12)
Example
println!("{}", value.bright_black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_red)
#### fn [bright\_red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightRed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-13)
Example
println!("{}", value.bright_red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_green)
#### fn [bright\_green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightGreen`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-14)
Example
println!("{}", value.bright_green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_yellow)
#### fn [bright\_yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightYellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-15)
Example
println!("{}", value.bright_yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_blue)
#### fn [bright\_blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightBlue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-16)
Example
println!("{}", value.bright_blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_magenta)
#### fn [bright\_magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightMagenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-17)
Example
println!("{}", value.bright_magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_cyan)
#### fn [bright\_cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightCyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-18)
Example
println!("{}", value.bright_cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright_white)
#### fn [bright\_white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightWhite`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-19)
Example
println!("{}", value.bright_white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bg)
#### fn [bg](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bg)
(&self, value: [Color](https://docs.rs/yansi/1.0.1/yansi/color/enum.Color.html "enum yansi::color::Color")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns a styled value derived from `self` with the background set to `value`.
This method should be used rarely. Instead, prefer to use color-specific builder methods like [`on_red()`](self::on_red())
and [`on_green()`](self::on_green())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-20)
Example
Set background color to red using `fg()`:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using [`on_red()`](self::on_red())
.
use yansi::Paint;
painted.on_red();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_primary)
#### fn [on\_primary](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_primary)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Primary`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-21)
Example
println!("{}", value.on_primary());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_fixed)
#### fn [on\_fixed](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_fixed)
(&self, color: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Fixed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-22)
Example
println!("{}", value.on_fixed(color));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_rgb)
#### fn [on\_rgb](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_rgb)
(&self, r: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, g: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, b: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Rgb`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-23)
Example
println!("{}", value.on_rgb(r, g, b));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_black)
#### fn [on\_black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Black`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-24)
Example
println!("{}", value.on_black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_red)
#### fn [on\_red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Red`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-25)
Example
println!("{}", value.on_red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_green)
#### fn [on\_green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Green`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-26)
Example
println!("{}", value.on_green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_yellow)
#### fn [on\_yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Yellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-27)
Example
println!("{}", value.on_yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_blue)
#### fn [on\_blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Blue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-28)
Example
println!("{}", value.on_blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_magenta)
#### fn [on\_magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Magenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-29)
Example
println!("{}", value.on_magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_cyan)
#### fn [on\_cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Cyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-30)
Example
println!("{}", value.on_cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_white)
#### fn [on\_white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: White`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-31)
Example
println!("{}", value.on_white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_black)
#### fn [on\_bright\_black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightBlack`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-32)
Example
println!("{}", value.on_bright_black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_red)
#### fn [on\_bright\_red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightRed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-33)
Example
println!("{}", value.on_bright_red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_green)
#### fn [on\_bright\_green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightGreen`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-34)
Example
println!("{}", value.on_bright_green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_yellow)
#### fn [on\_bright\_yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightYellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-35)
Example
println!("{}", value.on_bright_yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_blue)
#### fn [on\_bright\_blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightBlue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-36)
Example
println!("{}", value.on_bright_blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_magenta)
#### fn [on\_bright\_magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightMagenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-37)
Example
println!("{}", value.on_bright_magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_cyan)
#### fn [on\_bright\_cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightCyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-38)
Example
println!("{}", value.on_bright_cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright_white)
#### fn [on\_bright\_white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightWhite`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-39)
Example
println!("{}", value.on_bright_white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.attr)
#### fn [attr](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.attr)
(&self, value: [Attribute](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Attribute.html "enum yansi::attr_quirk::Attribute")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Enables the styling [`Attribute`](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Attribute.html "enum yansi::attr_quirk::Attribute")
`value`.
This method should be used rarely. Instead, prefer to use attribute-specific builder methods like [`bold()`](self::bold())
and [`underline()`](self::underline())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-40)
Example
Make text bold using `attr()`:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using [`bold()`](self::bold())
.
use yansi::Paint;
painted.bold();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bold)
#### fn [bold](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bold)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Bold`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-41)
Example
println!("{}", value.bold());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.dim)
#### fn [dim](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.dim)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Dim`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-42)
Example
println!("{}", value.dim());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.italic)
#### fn [italic](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.italic)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Italic`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-43)
Example
println!("{}", value.italic());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.underline)
#### fn [underline](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.underline)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Underline`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-44)
Example
println!("{}", value.underline());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.blink)
#### fn [blink](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.blink)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Blink`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-45)
Example
println!("{}", value.blink());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.rapid_blink)
#### fn [rapid\_blink](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.rapid_blink)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: RapidBlink`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-46)
Example
println!("{}", value.rapid_blink());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.invert)
#### fn [invert](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.invert)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Invert`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-47)
Example
println!("{}", value.invert());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.conceal)
#### fn [conceal](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.conceal)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Conceal`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-48)
Example
println!("{}", value.conceal());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.strike)
#### fn [strike](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.strike)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Strike`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-49)
Example
println!("{}", value.strike());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.quirk)
#### fn [quirk](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.quirk)
(&self, value: [Quirk](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Quirk.html "enum yansi::attr_quirk::Quirk")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Enables the `yansi` [`Quirk`](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Quirk.html "enum yansi::attr_quirk::Quirk")
`value`.
This method should be used rarely. Instead, prefer to use quirk-specific builder methods like [`mask()`](self::mask())
and [`wrap()`](self::wrap())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-50)
Example
Enable wrapping using `.quirk()`:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using [`wrap()`](self::wrap())
.
use yansi::Paint;
painted.wrap();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.mask)
#### fn [mask](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.mask)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Mask`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-51)
Example
println!("{}", value.mask());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.wrap)
#### fn [wrap](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.wrap)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Wrap`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-52)
Example
println!("{}", value.wrap());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.linger)
#### fn [linger](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.linger)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Linger`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-53)
Example
println!("{}", value.linger());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.clear)
#### fn [clear](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.clear)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
👎Deprecated since 1.0.1: renamed to `resetting()` due to conflicts with `Vec::clear()`. The `clear()` method will be removed in a future release.
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Clear`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-54)
Example
println!("{}", value.clear());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.resetting)
#### fn [resetting](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.resetting)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Resetting`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-55)
Example
println!("{}", value.resetting());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.bright)
#### fn [bright](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Bright`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-56)
Example
println!("{}", value.bright());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.on_bright)
#### fn [on\_bright](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: OnBright`\].
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-57)
Example
println!("{}", value.on_bright());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.whenever)
#### fn [whenever](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.whenever)
(&self, value: [Condition](https://docs.rs/yansi/1.0.1/yansi/condition/struct.Condition.html "struct yansi::condition::Condition")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Conditionally enable styling based on whether the [`Condition`](https://docs.rs/yansi/1.0.1/yansi/condition/struct.Condition.html "struct yansi::condition::Condition")
`value` applies. Replaces any previous condition.
See the [crate level docs](https://docs.rs/yansi/1.0.1/yansi/index.html#per-style "mod yansi")
for more details.
##### [§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#example-58)
Example
Enable styling `painted` only when both `stdout` and `stderr` are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#104)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.new)
#### fn [new](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.new)
(self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
where Self: [Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
Create a new [`Painted`](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
with a default [`Style`](https://docs.rs/yansi/1.0.1/yansi/style/struct.Style.html "struct yansi::style::Style")
. [Read more](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.new)
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#126)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.paint)
#### fn [paint](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.paint)
(&self, style: S) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<&Self>
where S: [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
<[Style](https://docs.rs/yansi/1.0.1/yansi/style/struct.Style.html "struct yansi::style::Style")
\>,
Apply a style wholesale to `self`. Any previous style is replaced. [Read more](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.paint)
[Source](https://docs.rs/typenum/1.19.0/src/typenum/type_operators.rs.html#34)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-Same-for-T)
### impl [Same](https://docs.rs/typenum/1.19.0/typenum/type_operators/trait.Same.html "trait typenum::type_operators::Same")
for T
[Source](https://docs.rs/typenum/1.19.0/src/typenum/type_operators.rs.html#35)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#associatedtype.Output)
#### type [Output](https://docs.rs/typenum/1.19.0/typenum/type_operators/trait.Same.html#associatedtype.Output)
= T
Should always be `Self`
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#827-829)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-TryFrom%3CU%3E-for-T)
### impl [TryFrom](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom")
for T
where U: [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
,
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#831)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#associatedtype.Error-1)
#### type [Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error)
= [Infallible](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/enum.Infallible.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Infallible")
The type returned in the event of a conversion error.
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#834)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.try_from)
#### fn [try\_from](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#tymethod.try_from)
(value: U) -> [Result](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/result/enum.Result.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::result::Result")
>::[Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error "type rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom::Error")
\>
Performs the conversion.
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#811-813)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-TryInto%3CU%3E-for-T)
### impl [TryInto](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryInto.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryInto")
for T
where U: [TryFrom](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom")
,
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#815)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#associatedtype.Error)
#### type [Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryInto.html#associatedtype.Error)
= >::[Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error "type rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom::Error")
The type returned in the event of a conversion error.
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#818)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.try_into)
#### fn [try\_into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryInto.html#tymethod.try_into)
(self) -> [Result](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/result/enum.Result.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::result::Result")
>::[Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error "type rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom::Error")
\>
Performs the conversion.
[Source](https://docs.rs/ppv-lite86/0.2.21/src/ppv_lite86/types.rs.html#221-223)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-VZip%3CV%3E-for-T)
### impl [VZip](https://docs.rs/ppv-lite86/0.2.21/ppv_lite86/types/trait.VZip.html "trait ppv_lite86::types::VZip")
for T
where V: [MultiLane](https://docs.rs/ppv-lite86/0.2.21/ppv_lite86/types/trait.MultiLane.html "trait ppv_lite86::types::MultiLane")
,
[Source](https://docs.rs/ppv-lite86/0.2.21/src/ppv_lite86/types.rs.html#226)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.vzip)
#### fn [vzip](https://docs.rs/ppv-lite86/0.2.21/ppv_lite86/types/trait.VZip.html#tymethod.vzip)
(self) -> V
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#393)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#impl-WithSubscriber-for-T)
### impl [WithSubscriber](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html "trait tracing::instrument::WithSubscriber")
for T
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#176-178)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.with_subscriber)
#### fn [with\_subscriber](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_subscriber)
(self, subscriber: S) -> [WithDispatch](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
[ⓘ](https://api.rocket.rs/v0.5/rocket/enum.Ignite#)
where S: [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
<[Dispatch](https://docs.rs/tracing-core/0.1.36/tracing_core/dispatcher/struct.Dispatch.html "struct tracing_core::dispatcher::Dispatch")
\>,
Attaches the provided [`Subscriber`](https://docs.rs/tracing-core/0.1.36/tracing_core/subscriber/trait.Subscriber.html "trait tracing_core::subscriber::Subscriber")
to this type, returning a [`WithDispatch`](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_subscriber)
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#228)
[§](https://api.rocket.rs/v0.5/rocket/enum.Ignite#method.with_current_subscriber)
#### fn [with\_current\_subscriber](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber)
(self) -> [WithDispatch](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
[ⓘ](https://api.rocket.rs/v0.5/rocket/enum.Ignite#)
Attaches the current [default](https://docs.rs/tracing/0.1.44/tracing/dispatcher/index.html#setting-the-default-subscriber "mod tracing::dispatcher")
[`Subscriber`](https://docs.rs/tracing-core/0.1.36/tracing_core/subscriber/trait.Subscriber.html "trait tracing_core::subscriber::Subscriber")
to this type, returning a [`WithDispatch`](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber)
---
# Sentinel in rocket - Rust
[Sentinel](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#)
--------------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Trait Sentinel Copy item path
=============================
[Source](https://api.rocket.rs/v0.5/src/rocket/sentinel.rs.html#278-281)
pub trait Sentinel {
// Required method
fn abort(rocket: &Rocket) -> bool;
}
Expand description
An automatic last line of defense against launching an invalid [`Rocket`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html "struct rocket::Rocket")
.
A sentinel, automatically run on [`ignition`](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html#method.ignite "method rocket::Rocket::ignite")
, can trigger a launch abort should an instance fail to meet arbitrary conditions. Every type that appears in a **mounted** route’s type signature is eligible to be a sentinel. Of these, those that implement `Sentinel` have their [`abort()`](https://api.rocket.rs/v0.5/rocket/trait.Sentinel.html#tymethod.abort "associated function rocket::Sentinel::abort")
method invoked automatically, immediately after ignition, once for each unique type. Sentinels inspect the finalized instance of `Rocket` and can trigger a launch abort by returning `true`.
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#built-in-sentinels)
Built-In Sentinels
-------------------------------------------------------------------------------------------
The [`State`](https://api.rocket.rs/v0.5/rocket/struct.State.html "struct rocket::State")
type is a sentinel that triggers an abort if the finalized `Rocket` instance is not managing state for type `T`. Doing so prevents run-time failures of the `State` request guard.
### [§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#example)
Example
As an example, consider the following simple application:
#[get("/")]
fn index(id: usize, state: &State) -> Response {
/* ... */
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}
At ignition time, effected by the `#[launch]` attribute here, Rocket probes all types in all mounted routes for `Sentinel` implementations. In this example, the types are: `usize`, `State`, and `Response`. Those that implement `Sentinel` are queried for an abort trigger via their [`Sentinel::abort()`](https://api.rocket.rs/v0.5/rocket/trait.Sentinel.html#tymethod.abort "associated function rocket::Sentinel::abort")
method. In this example, the sentinel types are [`State`](https://api.rocket.rs/v0.5/rocket/struct.State.html "struct rocket::State")
and _potentially_ `Response`, if it implements `Sentinel`. If `abort()` returns true, launch is aborted with a corresponding error.
In this example, launch will be aborted because state of type `String` is not being managed. To correct the error and allow launching to proceed nominally, a value of type `String` must be managed:
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![index])
.manage(String::from("my managed string"))
}
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#embedded-sentinels)
Embedded Sentinels
-------------------------------------------------------------------------------------------
Embedded types – type parameters of already eligible types – are also eligible to be sentinels. Consider the following route:
#[get("/")]
fn f(guard: Option<&State>) -> Either> {
unimplemented!()
}
The directly eligible sentinel types, guard and responders, are:
* `Option<&State>`
* `Either>`
In addition, all embedded types are _also_ eligible. These are:
* `&State`
* `State`
* `String`
* `Foo`
* `Inner`
* `Bar`
A type, whether embedded or not, is queried if it is a `Sentinel` _and_ none of its parent types are sentinels. Said a different way, if every _directly_ eligible type is viewed as the root of an acyclic graph with edges between a type and its type parameters, the _first_ `Sentinel` in breadth-first order is queried:
1. Option<&State> Either>
| / \
2. &State Foo Inner
| |
3. State Bar
|
4. String
In each graph above, types are queried from top to bottom, level 1 to 4. Querying continues down paths where the parents were _not_ sentinels. For example, if `Option` is a sentinel but `Either` is not, then querying stops for the left subgraph (`Option`) but continues for the right subgraph `Either`.
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#limitations)
Limitations
-----------------------------------------------------------------------------
Because Rocket must know which `Sentinel` implementation to query based on its _written_ type, generally only explicitly written, resolved, concrete types are eligible to be sentinels. A typical application will only work with such types, but there are several common cases to be aware of.
### [§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#impl-trait)
`impl Trait`
Occasionally an existential `impl Trait` may find its way into return types:
use rocket::response::Responder;
#[get("/")]
fn f<'r>() -> Either, AnotherSentinel> {
/* ... */
}
**Note:** _Rocket actively discourages using `impl Trait` in route signatures. In addition to impeding sentinel discovery, doing so decreases the ability to gleam a handler’s functionality based on its type signature._
The return type of the route `f` depends on its implementation. At present, it is not possible to name the underlying concrete type of an `impl Trait` at compile-time and thus not possible to determine if it implements `Sentinel`. As such, existentials _are not_ eligible to be sentinels.
That being said, this limitation only applies _per embedding_: types embedded inside of an `impl Trait` _are_ eligible. As such, in the example above, the named `AnotherSentinel` type continues to be eligible.
When possible, prefer to name all types:
#[get("/")]
fn f() -> Either {
/* ... */
}
### [§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#aliases)
Aliases
_Embedded_ sentinels made opaque by a type alias will fail to be considered; the aliased type itself _is_ considered. In the example below, only `Result` will be considered, while the embedded `Foo` and `Bar` will not.
type SomeAlias = Result;
#[get("/")]
fn f() -> SomeAlias {
/* ... */
}
Note, however, that `Option` and [`Debug`](https://api.rocket.rs/v0.5/rocket/response/struct.Debug.html "struct rocket::response::Debug")
are a sentinels if `T: Sentinel`, and `Result` and `Either` are sentinels if _both_ `T: Sentinel, E: Sentinel`. Thus, for these specific cases, a type alias _will_ “consider” embeddings. Nevertheless, prefer to write concrete types when possible.
### [§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#type-macros)
Type Macros
It is impossible to determine, a priori, what a type macro will expand to. As such, Rocket is unable to determine which sentinels, if any, a type macro references, and thus no sentinels are discovered from type macros.
Even approximations are impossible. For example, consider the following:
macro_rules! MyType {
(State<'_, u32>) => (&'_ rocket::Config)
}
#[get("/")]
fn f(guard: MyType![State<'_, u32>]) {
/* ... */
}
While the `MyType![State<'_, u32>]` type _appears_ to contain a `State` sentinel, the macro actually expands to `&'_ rocket::Config`, which is _not_ the `State` sentinel.
Because Rocket knows the exact syntax expected by type macros that it exports, such as the [typed stream](https://api.rocket.rs/v0.5/rocket/response/stream/index.html "mod rocket::response::stream")
macros, discovery in these macros works as expected. You should prefer not to use type macros aside from those exported by Rocket, or if necessary, restrict your use to those that always expand to types without sentinels.
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#custom-sentinels)
Custom Sentinels
---------------------------------------------------------------------------------------
Any type can implement `Sentinel`, and the implementation can arbitrarily inspect an ignited instance of `Rocket`. For illustration, consider the following implementation of `Sentinel` for a custom `Responder` which requires:
* state for a type `T` to be managed
* a catcher for status code `400` at base `/`
use rocket::{Rocket, Ignite, Sentinel};
impl Sentinel for MyResponder {
fn abort(rocket: &Rocket) -> bool {
if rocket.state::().is_none() {
return true;
}
if !rocket.catchers().any(|c| c.code == Some(400) && c.base == "/") {
return true;
}
false
}
}
If a `MyResponder` is returned by any mounted route, its `abort()` method will be invoked. If the required conditions aren’t met, signaled by returning `true` from `abort()`, Rocket aborts launch.
Required Methods[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#required-methods)
---------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/sentinel.rs.html#280)
#### fn [abort](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#tymethod.abort)
(rocket: &[Rocket](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html "struct rocket::Rocket")
<[Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
\>) -> [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
Returns `true` if launch should be aborted and `false` otherwise.
Dyn Compatibility[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#dyn-compatibility)
-----------------------------------------------------------------------------------------
This trait is **not** [dyn compatible](https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility)
.
_In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe._
Implementations on Foreign Types[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#foreign-impls)
----------------------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/sentinel.rs.html#304-310)
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#impl-Sentinel-for-Either%3CT,+E%3E)
### impl [Sentinel](https://api.rocket.rs/v0.5/rocket/trait.Sentinel.html "trait rocket::Sentinel")
for [Either](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
[Source](https://api.rocket.rs/v0.5/src/rocket/sentinel.rs.html#305-309)
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#method.abort)
#### fn [abort](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#tymethod.abort)
(rocket: &[Rocket](https://api.rocket.rs/v0.5/rocket/struct.Rocket.html "struct rocket::Rocket")
<[Ignite](https://api.rocket.rs/v0.5/rocket/enum.Ignite.html "enum rocket::Ignite")
\>) -> [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
Implementors[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#implementors)
-------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/sentinel.rs.html#314-318)
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#impl-Sentinel-for-Debug%3CT%3E)
### impl [Sentinel](https://api.rocket.rs/v0.5/rocket/trait.Sentinel.html "trait rocket::Sentinel")
for [Debug](https://api.rocket.rs/v0.5/rocket/response/struct.Debug.html "struct rocket::response::Debug")
A sentinel that never aborts. The `Responder` impl for `Debug` will never be called, so it’s okay to not abort for failing `T: Sentinel`.
[Source](https://api.rocket.rs/v0.5/src/rocket/state.rs.html#211-222)
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#impl-Sentinel-for-%26State%3CT%3E)
### impl [Sentinel](https://api.rocket.rs/v0.5/rocket/trait.Sentinel.html "trait rocket::Sentinel")
for &[State](https://api.rocket.rs/v0.5/rocket/struct.State.html "struct rocket::State")
[Source](https://api.rocket.rs/v0.5/src/rocket/sentinel.rs.html#283-287)
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#impl-Sentinel-for-Option%3CT%3E)
### impl [Sentinel](https://api.rocket.rs/v0.5/rocket/trait.Sentinel.html "trait rocket::Sentinel")
for [Option](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/option/enum.Option.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::option::Option")
[Source](https://api.rocket.rs/v0.5/src/rocket/sentinel.rs.html#296-302)
[§](https://api.rocket.rs/v0.5/rocket/trait.Sentinel#impl-Sentinel-for-Result%3CT,+E%3E)
### impl [Sentinel](https://api.rocket.rs/v0.5/rocket/trait.Sentinel.html "trait rocket::Sentinel")
for [Result](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/result/enum.Result.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::result::Result")
---
# Data in rocket - Rust
[Data](https://api.rocket.rs/v0.5/rocket/struct.Data#)
-------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Struct Data Copy item path
==========================
[Source](https://api.rocket.rs/v0.5/src/rocket/data/data.rs.html#40-44)
pub struct Data<'r> { /* private fields */ }
Expand description
Type representing the body data of a request.
This type is the only means by which the body of a request can be retrieved. This type is not usually used directly. Instead, data guards (types that implement [`FromData`](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
) are created indirectly via code generation by specifying the `data = ""` route parameter as follows:
#[post("/submit", data = "")]
fn submit(var: DataGuard) { /* ... */ }
Above, `DataGuard` can be any type that implements `FromData`. Note that `Data` itself implements `FromData`.
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#reading-data)
Reading Data
----------------------------------------------------------------------------
Data may be read from a `Data` object by calling either the [`open()`](https://api.rocket.rs/v0.5/rocket/struct.Data.html#method.open "method rocket::Data::open")
or [`peek()`](https://api.rocket.rs/v0.5/rocket/struct.Data.html#method.peek "method rocket::Data::peek")
methods.
The `open` method consumes the `Data` object and returns the raw data stream. The `Data` object is consumed for safety reasons: consuming the object ensures that holding a `Data` object means that all of the data is available for reading.
The `peek` method returns a slice containing at most 512 bytes of buffered body data. This enables partially or fully reading from a `Data` object without consuming the `Data` object.
Implementations[§](https://api.rocket.rs/v0.5/rocket/struct.Data#implementations)
----------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/data/data.rs.html#46-190)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Data%3C'r%3E)
### impl<'r> [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
[Source](https://api.rocket.rs/v0.5/src/rocket/data/data.rs.html#85-87)
#### pub fn [open](https://api.rocket.rs/v0.5/rocket/struct.Data#method.open)
(self, limit: [ByteUnit](https://api.rocket.rs/v0.5/rocket/data/struct.ByteUnit.html "struct rocket::data::ByteUnit")
) -> [DataStream](https://api.rocket.rs/v0.5/rocket/data/struct.DataStream.html "struct rocket::data::DataStream")
<'r>
Returns the raw data stream, limited to `limit` bytes.
The stream contains all of the data in the body of the request, including that in the `peek` buffer. The method consumes the `Data` instance. This ensures that a `Data` type _always_ represents _all_ of the data in a request.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example)
Example
use rocket::data::{Data, ToByteUnit};
fn handler(data: Data<'_>) {
let stream = data.open(2.mebibytes());
}
[Source](https://api.rocket.rs/v0.5/src/rocket/data/data.rs.html#150-169)
#### pub async fn [peek](https://api.rocket.rs/v0.5/rocket/struct.Data#method.peek)
(&mut self, num: [usize](https://doc.rust-lang.org/nightly/std/primitive.usize.html)
) -> &\[[u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)\
\] [ⓘ](https://api.rocket.rs/v0.5/rocket/struct.Data#)
Retrieve at most `num` bytes from the `peek` buffer without consuming `self`.
The peek buffer contains at most 512 bytes of the body of the request. The actual size of the returned buffer is the `min` of the request’s body, `num` and `512`. The [`peek_complete`](https://api.rocket.rs/v0.5/rocket/struct.Data#method.peek_complete)
method can be used to determine if this buffer contains _all_ of the data in the body of the request.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#examples)
Examples
In a data guard:
use rocket::request::{self, Request, FromRequest};
use rocket::data::{Data, FromData, Outcome};
use rocket::http::Status;
#[rocket::async_trait]
impl<'r> FromData<'r> for MyType {
type Error = MyError;
async fn from_data(r: &'r Request<'_>, mut data: Data<'r>) -> Outcome<'r, Self> {
if data.peek(2).await != b"hi" {
return Outcome::Forward((data, Status::BadRequest))
}
/* .. */
}
}
In a fairing:
use rocket::{Rocket, Request, Data, Response};
use rocket::fairing::{Fairing, Info, Kind};
#[rocket::async_trait]
impl Fairing for MyType {
fn info(&self) -> Info {
Info {
name: "Data Peeker",
kind: Kind::Request
}
}
async fn on_request(&self, req: &mut Request<'_>, data: &mut Data<'_>) {
if data.peek(2).await == b"hi" {
/* do something; body data starts with `"hi"` */
}
/* .. */
}
}
[Source](https://api.rocket.rs/v0.5/src/rocket/data/data.rs.html#187-189)
#### pub fn [peek\_complete](https://api.rocket.rs/v0.5/rocket/struct.Data#method.peek_complete)
(&self) -> [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
Returns true if the `peek` buffer contains all of the data in the body of the request. Returns `false` if it does not or if it is not known if it does.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-1)
Example
use rocket::data::Data;
async fn handler(mut data: Data<'_>) {
if data.peek_complete() {
println!("All of the data: {:?}", data.peek(512).await);
}
}
Trait Implementations[§](https://api.rocket.rs/v0.5/rocket/struct.Data#trait-implementations)
----------------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/data/from_data.rs.html#395-401)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-FromData%3C'r%3E-for-Data%3C'r%3E)
### impl<'r> [FromData](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html "trait rocket::data::FromData")
<'r> for [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
[Source](https://api.rocket.rs/v0.5/src/rocket/data/from_data.rs.html#396)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#associatedtype.Error)
#### type [Error](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html#associatedtype.Error)
= [Infallible](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/enum.Infallible.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Infallible")
The associated error to be returned when the guard fails.
[Source](https://api.rocket.rs/v0.5/src/rocket/data/from_data.rs.html#398-400)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.from_data)
#### fn [from\_data](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html#tymethod.from_data)
<'life0, 'async\_trait>( \_: &'r [Request](https://api.rocket.rs/v0.5/rocket/struct.Request.html "struct rocket::Request")
<'life0>, data: [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>, ) -> [Pin](https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html "struct core::pin::Pin")
<[Box](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/boxed/struct.Box.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box")
> + [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")
+ 'async\_trait>>
where Self: 'async\_trait, 'r: 'async\_trait, 'life0: 'async\_trait,
Asynchronously validates, parses, and converts an instance of `Self` from the incoming request body data. [Read more](https://api.rocket.rs/v0.5/rocket/data/trait.FromData.html#tymethod.from_data)
Auto Trait Implementations[§](https://api.rocket.rs/v0.5/rocket/struct.Data#synthetic-implementations)
-------------------------------------------------------------------------------------------------------
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Freeze-for-Data%3C'r%3E)
### impl<'r> 
for [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-RefUnwindSafe-for-Data%3C'r%3E)
### impl<'r> 
for [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Send-for-Data%3C'r%3E)
### impl<'r> [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")
for [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Sync-for-Data%3C'r%3E)
### impl<'r> [Sync](https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html "trait core::marker::Sync")
for [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Unpin-for-Data%3C'r%3E)
### impl<'r> [Unpin](https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html "trait core::marker::Unpin")
for [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-UnwindSafe-for-Data%3C'r%3E)
### impl<'r> 
for [Data](https://api.rocket.rs/v0.5/rocket/struct.Data.html "struct rocket::Data")
<'r>
Blanket Implementations[§](https://api.rocket.rs/v0.5/rocket/struct.Data#blanket-implementations)
--------------------------------------------------------------------------------------------------
[Source](https://doc.rust-lang.org/nightly/src/core/any.rs.html#138)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Any-for-T)
### impl [Any](https://doc.rust-lang.org/nightly/core/any/trait.Any.html "trait core::any::Any")
for T
where T: 'static + ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://doc.rust-lang.org/nightly/src/core/any.rs.html#139)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.type_id)
#### fn [type\_id](https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id)
(&self) -> [TypeId](https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html "struct core::any::TypeId")
Gets the `TypeId` of `self`. [Read more](https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id)
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#300)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-AsTaggedExplicit%3C'a%3E-for-T)
### impl<'a, T> [AsTaggedExplicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedExplicit.html "trait rocket::mtls::oid::asn1_rs::AsTaggedExplicit")
<'a> for T
where T: 'a,
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#295)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.explicit)
#### fn [explicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedExplicit.html#method.explicit)
(self, class: [Class](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Class.html "enum rocket::mtls::oid::asn1_rs::Class")
, tag: [u32](https://doc.rust-lang.org/nightly/std/primitive.u32.html)
) -> [TaggedParser](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/struct.TaggedParser.html "struct rocket::mtls::oid::asn1_rs::TaggedParser")
<'a, [Explicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Explicit.html "enum rocket::mtls::oid::asn1_rs::Explicit")
, Self>
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#323)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-AsTaggedImplicit%3C'a%3E-for-T)
### impl<'a, T> [AsTaggedImplicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedImplicit.html "trait rocket::mtls::oid::asn1_rs::AsTaggedImplicit")
<'a> for T
where T: 'a,
[Source](https://docs.rs/asn1-rs/0.3.1/src/asn1_rs/traits.rs.html#313-318)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.implicit)
#### fn [implicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/trait.AsTaggedImplicit.html#method.implicit)
( self, class: [Class](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Class.html "enum rocket::mtls::oid::asn1_rs::Class")
, constructed: [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
, tag: [u32](https://doc.rust-lang.org/nightly/std/primitive.u32.html)
, ) -> [TaggedParser](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/struct.TaggedParser.html "struct rocket::mtls::oid::asn1_rs::TaggedParser")
<'a, [Implicit](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/enum.Implicit.html "enum rocket::mtls::oid::asn1_rs::Implicit")
, Self>
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#212)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Borrow%3CT%3E-for-T)
### impl [Borrow](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html "trait core::borrow::Borrow")
for T
where T: ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#214)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.borrow)
#### fn [borrow](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow)
(&self) -> [&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
Immutably borrows from an owned value. [Read more](https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow)
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-BorrowMut%3CT%3E-for-T)
### impl [BorrowMut](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html "trait core::borrow::BorrowMut")
for T
where T: ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#222)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.borrow_mut)
#### fn [borrow\_mut](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut)
(&mut self) -> [&mut T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
Mutably borrows from an owned value. [Read more](https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut)
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#785)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-From%3CT%3E-for-T)
### impl [From](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::From")
for T
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#788)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.from)
#### fn [from](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html#tymethod.from)
(t: T) -> T
Returns the argument unchanged.
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#325)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Instrument-for-T)
### impl [Instrument](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html "trait tracing::instrument::Instrument")
for T
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#86)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.instrument)
#### fn [instrument](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.instrument)
(self, span: [Span](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html "struct tracing::span::Span")
) -> [Instrumented](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.Instrumented.html "struct tracing::instrument::Instrumented")
[ⓘ](https://api.rocket.rs/v0.5/rocket/struct.Data#)
Instruments this type with the provided [`Span`](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html "struct tracing::span::Span")
, returning an `Instrumented` wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.instrument)
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#128)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.in_current_span)
#### fn [in\_current\_span](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.in_current_span)
(self) -> [Instrumented](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.Instrumented.html "struct tracing::instrument::Instrumented")
[ⓘ](https://api.rocket.rs/v0.5/rocket/struct.Data#)
Instruments this type with the [current](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html#method.current "associated function tracing::span::Span::current")
[`Span`](https://docs.rs/tracing/0.1.44/tracing/span/struct.Span.html "struct tracing::span::Span")
, returning an `Instrumented` wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.Instrument.html#method.in_current_span)
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#767-769)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Into%3CU%3E-for-T)
### impl [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
for T
where U: [From](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::From")
,
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#777)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.into)
#### fn [into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html#tymethod.into)
(self) -> U
Calls `U::from(self)`.
That is, this conversion is whatever the implementation of `[From](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.From.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::From") for U` chooses to do.
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-IntoCollection%3CT%3E-for-T)
### impl [IntoCollection](https://api.rocket.rs/v0.5/rocket/http/ext/trait.IntoCollection.html "trait rocket::http::ext::IntoCollection")
for T
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.into_collection)
#### fn [into\_collection](https://api.rocket.rs/v0.5/rocket/http/ext/trait.IntoCollection.html#tymethod.into_collection)
(self) -> [SmallVec](https://docs.rs/smallvec/1.15.1/smallvec/struct.SmallVec.html "struct smallvec::SmallVec")
where A: [Array](https://docs.rs/smallvec/1.15.1/smallvec/trait.Array.html "trait smallvec::Array")
- ,
Converts `self` into a collection.
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.mapped)
#### fn [mapped](https://api.rocket.rs/v0.5/rocket/http/ext/trait.IntoCollection.html#tymethod.mapped)
(self, f: F) -> [SmallVec](https://docs.rs/smallvec/1.15.1/smallvec/struct.SmallVec.html "struct smallvec::SmallVec")
where F: [FnMut](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/ops/trait.FnMut.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::ops::FnMut")
(T) -> U, A: [Array](https://docs.rs/smallvec/1.15.1/smallvec/trait.Array.html "trait smallvec::Array")
- ,
[Source](https://docs.rs/either/1/src/either/into_either.rs.html#64)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-IntoEither-for-T)
### impl [IntoEither](https://docs.rs/either/1/either/into_either/trait.IntoEither.html "trait either::into_either::IntoEither")
for T
[Source](https://docs.rs/either/1/src/either/into_either.rs.html#29)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.into_either)
#### fn [into\_either](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either)
(self, into\_left: [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
) -> [Either](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
[ⓘ](https://api.rocket.rs/v0.5/rocket/struct.Data#)
Converts `self` into a [`Left`](https://docs.rs/either/1/either/enum.Either.html#variant.Left "variant either::Either::Left")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
if `into_left` is `true`. Converts `self` into a [`Right`](https://docs.rs/either/1/either/enum.Either.html#variant.Right "variant either::Either::Right")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
otherwise. [Read more](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either)
[Source](https://docs.rs/either/1/src/either/into_either.rs.html#55-57)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.into_either_with)
#### fn [into\_either\_with](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either_with)
(self, into\_left: F) -> [Either](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
[ⓘ](https://api.rocket.rs/v0.5/rocket/struct.Data#)
where F: [FnOnce](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/ops/trait.FnOnce.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::ops::FnOnce")
(&Self) -> [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)
,
Converts `self` into a [`Left`](https://docs.rs/either/1/either/enum.Either.html#variant.Left "variant either::Either::Left")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
if `into_left(&self)` returns `true`. Converts `self` into a [`Right`](https://docs.rs/either/1/either/enum.Either.html#variant.Right "variant either::Either::Right")
variant of [`Either`](https://docs.rs/either/1/either/enum.Either.html "enum either::Either")
otherwise. [Read more](https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either_with)
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#134)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Paint-for-T)
### impl [Paint](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html "trait yansi::paint::Paint")
for T
where T: ?[Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.fg)
#### fn [fg](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.fg)
(&self, value: [Color](https://docs.rs/yansi/1.0.1/yansi/color/enum.Color.html "enum yansi::color::Color")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns a styled value derived from `self` with the foreground set to `value`.
This method should be used rarely. Instead, prefer to use color-specific builder methods like [`red()`](self::red())
and [`green()`](self::green())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-2)
Example
Set foreground color to white using `fg()`:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using [`white()`](self::white())
.
use yansi::Paint;
painted.white();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.primary)
#### fn [primary](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.primary)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Primary`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-3)
Example
println!("{}", value.primary());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.fixed)
#### fn [fixed](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.fixed)
(&self, color: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Fixed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-4)
Example
println!("{}", value.fixed(color));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.rgb)
#### fn [rgb](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.rgb)
(&self, r: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, g: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, b: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Rgb`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-5)
Example
println!("{}", value.rgb(r, g, b));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.black)
#### fn [black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Black`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-6)
Example
println!("{}", value.black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.red)
#### fn [red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Red`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-7)
Example
println!("{}", value.red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.green)
#### fn [green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Green`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-8)
Example
println!("{}", value.green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.yellow)
#### fn [yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Yellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-9)
Example
println!("{}", value.yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.blue)
#### fn [blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Blue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-10)
Example
println!("{}", value.blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.magenta)
#### fn [magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Magenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-11)
Example
println!("{}", value.magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.cyan)
#### fn [cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: Cyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-12)
Example
println!("{}", value.cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.white)
#### fn [white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: White`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-13)
Example
println!("{}", value.white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_black)
#### fn [bright\_black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightBlack`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-14)
Example
println!("{}", value.bright_black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_red)
#### fn [bright\_red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightRed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-15)
Example
println!("{}", value.bright_red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_green)
#### fn [bright\_green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightGreen`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-16)
Example
println!("{}", value.bright_green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_yellow)
#### fn [bright\_yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightYellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-17)
Example
println!("{}", value.bright_yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_blue)
#### fn [bright\_blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightBlue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-18)
Example
println!("{}", value.bright_blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_magenta)
#### fn [bright\_magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightMagenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-19)
Example
println!("{}", value.bright_magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_cyan)
#### fn [bright\_cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightCyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-20)
Example
println!("{}", value.bright_cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright_white)
#### fn [bright\_white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright_white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`fg()`](self::fg())
set to \[`Color :: BrightWhite`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-21)
Example
println!("{}", value.bright_white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bg)
#### fn [bg](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bg)
(&self, value: [Color](https://docs.rs/yansi/1.0.1/yansi/color/enum.Color.html "enum yansi::color::Color")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns a styled value derived from `self` with the background set to `value`.
This method should be used rarely. Instead, prefer to use color-specific builder methods like [`on_red()`](self::on_red())
and [`on_green()`](self::on_green())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-22)
Example
Set background color to red using `fg()`:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using [`on_red()`](self::on_red())
.
use yansi::Paint;
painted.on_red();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_primary)
#### fn [on\_primary](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_primary)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Primary`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-23)
Example
println!("{}", value.on_primary());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_fixed)
#### fn [on\_fixed](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_fixed)
(&self, color: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Fixed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-24)
Example
println!("{}", value.on_fixed(color));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_rgb)
#### fn [on\_rgb](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_rgb)
(&self, r: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, g: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
, b: [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Rgb`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-25)
Example
println!("{}", value.on_rgb(r, g, b));
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_black)
#### fn [on\_black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Black`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-26)
Example
println!("{}", value.on_black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_red)
#### fn [on\_red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Red`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-27)
Example
println!("{}", value.on_red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_green)
#### fn [on\_green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Green`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-28)
Example
println!("{}", value.on_green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_yellow)
#### fn [on\_yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Yellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-29)
Example
println!("{}", value.on_yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_blue)
#### fn [on\_blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Blue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-30)
Example
println!("{}", value.on_blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_magenta)
#### fn [on\_magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Magenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-31)
Example
println!("{}", value.on_magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_cyan)
#### fn [on\_cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: Cyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-32)
Example
println!("{}", value.on_cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_white)
#### fn [on\_white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: White`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-33)
Example
println!("{}", value.on_white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_black)
#### fn [on\_bright\_black](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_black)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightBlack`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-34)
Example
println!("{}", value.on_bright_black());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_red)
#### fn [on\_bright\_red](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_red)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightRed`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-35)
Example
println!("{}", value.on_bright_red());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_green)
#### fn [on\_bright\_green](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_green)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightGreen`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-36)
Example
println!("{}", value.on_bright_green());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_yellow)
#### fn [on\_bright\_yellow](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_yellow)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightYellow`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-37)
Example
println!("{}", value.on_bright_yellow());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_blue)
#### fn [on\_bright\_blue](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_blue)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightBlue`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-38)
Example
println!("{}", value.on_bright_blue());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_magenta)
#### fn [on\_bright\_magenta](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_magenta)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightMagenta`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-39)
Example
println!("{}", value.on_bright_magenta());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_cyan)
#### fn [on\_bright\_cyan](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_cyan)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightCyan`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-40)
Example
println!("{}", value.on_bright_cyan());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright_white)
#### fn [on\_bright\_white](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright_white)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`bg()`](self::bg())
set to \[`Color :: BrightWhite`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-41)
Example
println!("{}", value.on_bright_white());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.attr)
#### fn [attr](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.attr)
(&self, value: [Attribute](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Attribute.html "enum yansi::attr_quirk::Attribute")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Enables the styling [`Attribute`](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Attribute.html "enum yansi::attr_quirk::Attribute")
`value`.
This method should be used rarely. Instead, prefer to use attribute-specific builder methods like [`bold()`](self::bold())
and [`underline()`](self::underline())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-42)
Example
Make text bold using `attr()`:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using [`bold()`](self::bold())
.
use yansi::Paint;
painted.bold();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bold)
#### fn [bold](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bold)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Bold`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-43)
Example
println!("{}", value.bold());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.dim)
#### fn [dim](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.dim)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Dim`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-44)
Example
println!("{}", value.dim());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.italic)
#### fn [italic](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.italic)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Italic`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-45)
Example
println!("{}", value.italic());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.underline)
#### fn [underline](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.underline)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Underline`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-46)
Example
println!("{}", value.underline());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.blink)
#### fn [blink](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.blink)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Blink`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-47)
Example
println!("{}", value.blink());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.rapid_blink)
#### fn [rapid\_blink](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.rapid_blink)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: RapidBlink`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-48)
Example
println!("{}", value.rapid_blink());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.invert)
#### fn [invert](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.invert)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Invert`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-49)
Example
println!("{}", value.invert());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.conceal)
#### fn [conceal](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.conceal)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Conceal`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-50)
Example
println!("{}", value.conceal());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.strike)
#### fn [strike](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.strike)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`attr()`](self::attr())
set to \[`Attribute :: Strike`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-51)
Example
println!("{}", value.strike());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.quirk)
#### fn [quirk](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.quirk)
(&self, value: [Quirk](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Quirk.html "enum yansi::attr_quirk::Quirk")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Enables the `yansi` [`Quirk`](https://docs.rs/yansi/1.0.1/yansi/attr_quirk/enum.Quirk.html "enum yansi::attr_quirk::Quirk")
`value`.
This method should be used rarely. Instead, prefer to use quirk-specific builder methods like [`mask()`](self::mask())
and [`wrap()`](self::wrap())
, which have the same functionality but are pithier.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-52)
Example
Enable wrapping using `.quirk()`:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using [`wrap()`](self::wrap())
.
use yansi::Paint;
painted.wrap();
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.mask)
#### fn [mask](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.mask)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Mask`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-53)
Example
println!("{}", value.mask());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.wrap)
#### fn [wrap](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.wrap)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Wrap`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-54)
Example
println!("{}", value.wrap());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.linger)
#### fn [linger](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.linger)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Linger`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-55)
Example
println!("{}", value.linger());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.clear)
#### fn [clear](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.clear)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
👎Deprecated since 1.0.1: renamed to `resetting()` due to conflicts with `Vec::clear()`. The `clear()` method will be removed in a future release.
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Clear`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-56)
Example
println!("{}", value.clear());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.resetting)
#### fn [resetting](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.resetting)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Resetting`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-57)
Example
println!("{}", value.resetting());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.bright)
#### fn [bright](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.bright)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: Bright`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-58)
Example
println!("{}", value.bright());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.on_bright)
#### fn [on\_bright](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.on_bright)
(&self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Returns `self` with the [`quirk()`](self::quirk())
set to \[`Quirk :: OnBright`\].
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-59)
Example
println!("{}", value.on_bright());
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#135)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.whenever)
#### fn [whenever](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#tymethod.whenever)
(&self, value: [Condition](https://docs.rs/yansi/1.0.1/yansi/condition/struct.Condition.html "struct yansi::condition::Condition")
) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<[&T](https://doc.rust-lang.org/nightly/std/primitive.reference.html)
\>
Conditionally enable styling based on whether the [`Condition`](https://docs.rs/yansi/1.0.1/yansi/condition/struct.Condition.html "struct yansi::condition::Condition")
`value` applies. Replaces any previous condition.
See the [crate level docs](https://docs.rs/yansi/1.0.1/yansi/index.html#per-style "mod yansi")
for more details.
##### [§](https://api.rocket.rs/v0.5/rocket/struct.Data#example-60)
Example
Enable styling `painted` only when both `stdout` and `stderr` are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#104)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.new)
#### fn [new](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.new)
(self) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
where Self: [Sized](https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html "trait core::marker::Sized")
,
Create a new [`Painted`](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
with a default [`Style`](https://docs.rs/yansi/1.0.1/yansi/style/struct.Style.html "struct yansi::style::Style")
. [Read more](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.new)
[Source](https://docs.rs/yansi/1.0.1/src/yansi/paint.rs.html#126)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.paint)
#### fn [paint](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.paint)
(&self, style: S) -> [Painted](https://docs.rs/yansi/1.0.1/yansi/paint/struct.Painted.html "struct yansi::paint::Painted")
<&Self>
where S: [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
<[Style](https://docs.rs/yansi/1.0.1/yansi/style/struct.Style.html "struct yansi::style::Style")
\>,
Apply a style wholesale to `self`. Any previous style is replaced. [Read more](https://docs.rs/yansi/1.0.1/yansi/paint/trait.Paint.html#method.paint)
[Source](https://docs.rs/typenum/1.19.0/src/typenum/type_operators.rs.html#34)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-Same-for-T)
### impl [Same](https://docs.rs/typenum/1.19.0/typenum/type_operators/trait.Same.html "trait typenum::type_operators::Same")
for T
[Source](https://docs.rs/typenum/1.19.0/src/typenum/type_operators.rs.html#35)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#associatedtype.Output)
#### type [Output](https://docs.rs/typenum/1.19.0/typenum/type_operators/trait.Same.html#associatedtype.Output)
= T
Should always be `Self`
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#827-829)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-TryFrom%3CU%3E-for-T)
### impl [TryFrom](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom")
for T
where U: [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
,
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#831)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#associatedtype.Error-2)
#### type [Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error)
= [Infallible](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/enum.Infallible.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Infallible")
The type returned in the event of a conversion error.
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#834)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.try_from)
#### fn [try\_from](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#tymethod.try_from)
(value: U) -> [Result](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/result/enum.Result.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::result::Result")
>::[Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error "type rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom::Error")
\>
Performs the conversion.
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#811-813)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-TryInto%3CU%3E-for-T)
### impl [TryInto](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryInto.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryInto")
for T
where U: [TryFrom](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom")
,
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#815)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#associatedtype.Error-1)
#### type [Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryInto.html#associatedtype.Error)
= >::[Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error "type rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom::Error")
The type returned in the event of a conversion error.
[Source](https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#818)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.try_into)
#### fn [try\_into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryInto.html#tymethod.try_into)
(self) -> [Result](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/result/enum.Result.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::result::Result")
>::[Error](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.TryFrom.html#associatedtype.Error "type rocket::mtls::oid::asn1_rs::nom::lib::std::convert::TryFrom::Error")
\>
Performs the conversion.
[Source](https://docs.rs/ppv-lite86/0.2.21/src/ppv_lite86/types.rs.html#221-223)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-VZip%3CV%3E-for-T)
### impl [VZip](https://docs.rs/ppv-lite86/0.2.21/ppv_lite86/types/trait.VZip.html "trait ppv_lite86::types::VZip")
for T
where V: [MultiLane](https://docs.rs/ppv-lite86/0.2.21/ppv_lite86/types/trait.MultiLane.html "trait ppv_lite86::types::MultiLane")
,
[Source](https://docs.rs/ppv-lite86/0.2.21/src/ppv_lite86/types.rs.html#226)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.vzip)
#### fn [vzip](https://docs.rs/ppv-lite86/0.2.21/ppv_lite86/types/trait.VZip.html#tymethod.vzip)
(self) -> V
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#393)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#impl-WithSubscriber-for-T)
### impl [WithSubscriber](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html "trait tracing::instrument::WithSubscriber")
for T
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#176-178)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.with_subscriber)
#### fn [with\_subscriber](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_subscriber)
(self, subscriber: S) -> [WithDispatch](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
[ⓘ](https://api.rocket.rs/v0.5/rocket/struct.Data#)
where S: [Into](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/convert/trait.Into.html "trait rocket::mtls::oid::asn1_rs::nom::lib::std::convert::Into")
<[Dispatch](https://docs.rs/tracing-core/0.1.36/tracing_core/dispatcher/struct.Dispatch.html "struct tracing_core::dispatcher::Dispatch")
\>,
Attaches the provided [`Subscriber`](https://docs.rs/tracing-core/0.1.36/tracing_core/subscriber/trait.Subscriber.html "trait tracing_core::subscriber::Subscriber")
to this type, returning a [`WithDispatch`](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_subscriber)
[Source](https://docs.rs/tracing/0.1.44/src/tracing/instrument.rs.html#228)
[§](https://api.rocket.rs/v0.5/rocket/struct.Data#method.with_current_subscriber)
#### fn [with\_current\_subscriber](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber)
(self) -> [WithDispatch](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
[ⓘ](https://api.rocket.rs/v0.5/rocket/struct.Data#)
Attaches the current [default](https://docs.rs/tracing/0.1.44/tracing/dispatcher/index.html#setting-the-default-subscriber "mod tracing::dispatcher")
[`Subscriber`](https://docs.rs/tracing-core/0.1.36/tracing_core/subscriber/trait.Subscriber.html "trait tracing_core::subscriber::Subscriber")
to this type, returning a [`WithDispatch`](https://docs.rs/tracing/0.1.44/tracing/instrument/struct.WithDispatch.html "struct tracing::instrument::WithDispatch")
wrapper. [Read more](https://docs.rs/tracing/0.1.44/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber)
---
# rocket::response - Rust
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
[Module response](https://api.rocket.rs/v0.5/rocket/response/index.html#)
--------------------------------------------------------------------------
[](https://api.rocket.rs/v0.5/rocket/all.html "show sidebar")
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Module response Copy item path
==============================
[Source](https://api.rocket.rs/v0.5/src/rocket/response/mod.rs.html#1-39)
[Search](https://api.rocket.rs/v0.5/rocket/response/?search=)
[Settings](https://api.rocket.rs/v0.5/settings.html)
[Help](https://api.rocket.rs/v0.5/help.html)
Summary
Expand description
Types and traits to build and send responses.
The return type of a Rocket handler can be any type that implements the [`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html "trait rocket::response::Responder")
trait, which means that the type knows how to generate a [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html "struct rocket::Response")
. Among other things, this module contains several such types.
[§](https://api.rocket.rs/v0.5/rocket/response/index.html#composing)
Composing
------------------------------------------------------------------------------
Many of the built-in `Responder` types _chain_ responses: they take in another `Responder` and add, remove, or change information in the response. In other words, many `Responder` types are built to compose well. As a result, you’ll often have types of the form `A>` consisting of three `Responder`s `A`, `B`, and `C`. This is normal and encouraged as the type names typically illustrate the intended response.
Modules[§](https://api.rocket.rs/v0.5/rocket/response/index.html#modules)
--------------------------------------------------------------------------
[content](https://api.rocket.rs/v0.5/rocket/response/content/index.html "mod rocket::response::content")
Contains types that set the Content-Type of a response.
[status](https://api.rocket.rs/v0.5/rocket/response/status/index.html "mod rocket::response::status")
Contains types that set the status code and corresponding headers of a response.
[stream](https://api.rocket.rs/v0.5/rocket/response/stream/index.html "mod rocket::response::stream")
Potentially infinite async [`Stream`](https://docs.rs/futures/0.3/futures/stream/trait.Stream.html)
response types.
Structs[§](https://api.rocket.rs/v0.5/rocket/response/index.html#structs)
--------------------------------------------------------------------------
[Body](https://api.rocket.rs/v0.5/rocket/response/struct.Body.html "struct rocket::response::Body")
The body of a [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html "struct rocket::Response")
.
[Builder](https://api.rocket.rs/v0.5/rocket/response/struct.Builder.html "struct rocket::response::Builder")
Builder for the [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html "struct rocket::Response")
type.
[Debug](https://api.rocket.rs/v0.5/rocket/response/struct.Debug.html "struct rocket::response::Debug")
Debug prints the internal value before forwarding to the 500 error catcher.
[Flash](https://api.rocket.rs/v0.5/rocket/response/struct.Flash.html "struct rocket::response::Flash")
Sets a “flash” cookie that will be removed when it is accessed. The analogous request type is [`FlashMessage`](https://api.rocket.rs/v0.5/rocket/request/type.FlashMessage.html "type rocket::request::FlashMessage")
.
[Redirect](https://api.rocket.rs/v0.5/rocket/response/struct.Redirect.html "struct rocket::response::Redirect")
An empty redirect response to a given URL.
[Response](https://api.rocket.rs/v0.5/rocket/response/struct.Response.html "struct rocket::response::Response")
A response, as returned by types implementing [`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html "trait rocket::response::Responder")
.
Traits[§](https://api.rocket.rs/v0.5/rocket/response/index.html#traits)
------------------------------------------------------------------------
[Responder](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html "trait rocket::response::Responder")
Trait implemented by types that generate responses for clients.
Type Aliases[§](https://api.rocket.rs/v0.5/rocket/response/index.html#types)
-----------------------------------------------------------------------------
[Result](https://api.rocket.rs/v0.5/rocket/response/type.Result.html "type rocket::response::Result")
Type alias for the `Result` of a [`Responder::respond_to()`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html#tymethod.respond_to "method rocket::response::Responder::respond_to")
call.
---
# FromFormField in rocket - Rust
[FromFormField](https://api.rocket.rs/v0.5/rocket/derive.FromFormField#)
-------------------------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Derive Macro FromFormField Copy item path
=========================================
[Source](https://api.rocket.rs/v0.5/src/rocket_codegen/lib.rs.html#545)
#[derive(FromFormField)]
{
// Attributes available to this derive:
#[field]
}
Expand description
Derive for the [`FromFormField`](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html)
trait.
The [`FromFormField`](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html)
derive can be applied to enums with nullary (zero-length) fields:
#[derive(FromFormField)]
enum MyValue {
First,
Second,
Third,
}
The derive generates an implementation of the [`FromFormField`](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html)
trait for the decorated `enum`. The implementation returns successfully when the form value matches, case insensitively, the stringified version of a variant’s name, returning an instance of said variant. If there is no match, an error recording all of the available options is returned.
As an example, for the `enum` above, the form values `"first"`, `"FIRST"`, `"fiRSt"`, and so on would parse as `MyValue::First`, while `"second"` and `"third"` (in any casing) would parse as `MyValue::Second` and `MyValue::Third`, respectively.
The `field` field attribute can be used to change the string value that is compared against for a given variant:
#[derive(FromFormField)]
enum MyValue {
First,
Second,
#[field(value = "fourth")]
#[field(value = "fifth")]
Third,
}
When more than one `value` is specified, matching _any_ value will result in parsing the decorated variant. Declaring any two values that are case-insensitively equal to any other value or variant name is a compile-time error.
The `#[field]` attribute’s grammar is:
field := 'value' '=' STRING_LIT
STRING_LIT := any valid string literal, as defined by Rust
The attribute accepts a single string parameter of name `value` corresponding to the string to use to match against for the decorated variant. In the example above, the the strings `"fourth"`, `"FOUrth"`, `"fiFTH"` and so on would parse as `MyValue::Third`.
---
# UriDisplayPath in rocket - Rust
[UriDisplayPath](https://api.rocket.rs/v0.5/rocket/derive.UriDisplayPath#)
---------------------------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Derive Macro UriDisplayPath Copy item path
==========================================
[Source](https://api.rocket.rs/v0.5/src/rocket_codegen/lib.rs.html#1059)
#[derive(UriDisplayPath)]
Expand description
Derive for the [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
trait.
The [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
derive can only be applied to tuple structs with one field.
#[derive(UriDisplayPath)]
struct Name(String);
#[derive(UriDisplayPath)]
struct Age(usize);
The field’s type is required to implement [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
.
The derive generates an implementation of the [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
trait. The implementation calls [`Formatter::write_value()`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/struct.Formatter.html#method.write_value)
for the field.
---
# UriDisplayQuery in rocket - Rust
[UriDisplayQuery](https://api.rocket.rs/v0.5/rocket/derive.UriDisplayQuery#)
-----------------------------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Derive Macro UriDisplayQuery Copy item path
===========================================
[Source](https://api.rocket.rs/v0.5/src/rocket_codegen/lib.rs.html#1033)
#[derive(UriDisplayQuery)]
{
// Attributes available to this derive:
#[field]
}
Expand description
Derive for the [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
trait.
The [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
derive can be applied to enums and structs. When applied to an enum, the enum must have at least one variant. When applied to a struct, the struct must have at least one field.
#[derive(UriDisplayQuery)]
enum Kind {
A(String),
B(usize),
}
#[derive(UriDisplayQuery)]
struct MyStruct {
name: String,
id: usize,
kind: Kind,
}
Each field’s type is required to implement [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
.
The derive generates an implementation of the [`UriDisplay`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/trait.UriDisplay.html)
trait. The implementation calls [`Formatter::write_named_value()`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/struct.Formatter.html#method.write_named_value)
for every named field, using the field’s name (unless overridden, explained next) as the `name` parameter, and [`Formatter::write_value()`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/struct.Formatter.html#method.write_value)
for every unnamed field in the order the fields are declared.
The derive accepts one field attribute: `field`, with the following syntax:
field := 'name' '=' '"' FIELD_NAME '"'
| 'value' '=' '"' FIELD_VALUE '"'
FIELD_NAME := valid HTTP field name
FIELD_VALUE := valid HTTP field value
When applied to a struct, the attribute can only contain `name` and looks as follows:
#[derive(UriDisplayQuery)]
struct MyStruct {
name: String,
id: usize,
#[field(name = "type")]
#[field(name = "kind")]
kind: Kind,
}
The field attribute directs that a different field name be used when calling [`Formatter::write_named_value()`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/struct.Formatter.html#method.write_named_value)
for the given field. The value of the `name` attribute is used instead of the structure’s actual field name. If more than one `field` attribute is applied to a field, the _first_ name is used. In the example above, the field `MyStruct::kind` is rendered with a name of `type`.
The attribute can also be applied to variants of C-like enums; it may only contain `value` and looks as follows:
#[derive(UriDisplayQuery)]
enum Kind {
File,
#[field(value = "str")]
#[field(value = "string")]
String,
Other
}
The field attribute directs that a different value be used when calling [`Formatter::write_named_value()`](https://api.rocket.rs/v0.5/rocket/http/uri/fmt/struct.Formatter.html#method.write_named_value)
for the given variant. The value of the `value` attribute is used instead of the variant’s actual name. If more than one `field` attribute is applied to a variant, the _first_ value is used. In the example above, the variant `Kind::String` will render with a value of `str`.
---
# Responder in rocket - Rust
[Responder](https://api.rocket.rs/v0.5/rocket/derive.Responder#)
-----------------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
Derive Macro Responder Copy item path
=====================================
[Source](https://api.rocket.rs/v0.5/src/rocket_codegen/lib.rs.html#939)
#[derive(Responder)]
{
// Attributes available to this derive:
#[response]
}
Expand description
Derive for the [`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html)
trait.
The [`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html)
derive can be applied to enums and structs with named fields. When applied to enums, variants must have at least one field. When applied to structs, the struct must have at least one field.
#[derive(Responder)]
enum MyResponderA {
A(String),
B(File, ContentType),
}
#[derive(Responder)]
struct MyResponderB {
inner: OtherResponder,
header: ContentType,
}
[§](https://api.rocket.rs/v0.5/rocket/derive.Responder#semantics)
Semantics
---------------------------------------------------------------------------
The derive generates an implementation of the [`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html)
trait for the decorated enum or structure. The derive uses the _first_ field of a variant or structure to generate a [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html)
. As such, the type of the first field must implement [`Responder`](https://api.rocket.rs/v0.5/rocket/response/trait.Responder.html)
. The remaining fields of a variant or structure are set as headers in the produced [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html)
using [`Response::set_header()`](https://api.rocket.rs/v0.5/rocket/response/struct.Response.html#method.set_header)
. As such, every other field (unless explicitly ignored, explained next) must implement `Into`.
Except for the first field, fields decorated with `#[response(ignore)]` are ignored by the derive:
#[derive(Responder)]
enum MyResponder {
A(String),
B(File, ContentType, #[response(ignore)] Other),
}
#[derive(Responder)]
struct MyOtherResponder {
inner: NamedFile,
header: ContentType,
#[response(ignore)]
other: Other,
}
Decorating the first field with `#[response(ignore)]` has no effect.
[§](https://api.rocket.rs/v0.5/rocket/derive.Responder#field-attribute)
Field Attribute
---------------------------------------------------------------------------------------
Additionally, the `response` attribute can be used on named structures and enum variants to override the status and/or content-type of the [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html)
produced by the generated implementation. The `response` attribute used in these positions has the following grammar:
response := parameter (',' parameter)?
parameter := 'status' '=' STATUS
| 'content_type' '=' CONTENT_TYPE
STATUS := unsigned integer >= 100 and < 600
CONTENT_TYPE := string literal, as defined by Rust, identifying a valid
Content-Type, as defined by Rocket
It can be used as follows:
#[derive(Responder)]
enum Error {
#[response(status = 500, content_type = "json")]
A(String),
#[response(status = 404)]
B(NamedFile, ContentType),
}
#[derive(Responder)]
#[response(status = 400)]
struct MyResponder {
inner: InnerResponder,
header: ContentType,
#[response(ignore)]
other: Other,
}
The attribute accepts two key/value pairs: `status` and `content_type`. The value of `status` must be an unsigned integer representing a valid status code. The [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html)
produced from the generated implementation will have its status overridden to this value.
The value of `content_type` must be a valid media-type in `top/sub` form or `shorthand` form. Examples include:
* `"text/html"`
* `"application/x-custom"`
* `"html"`
* `"json"`
* `"plain"`
* `"binary"`
See [`ContentType::parse_flexible()`](https://api.rocket.rs/v0.5/rocket/http/struct.ContentType.html#method.parse_flexible)
for a full list of available shorthands. The [`Response`](https://api.rocket.rs/v0.5/rocket/struct.Response.html)
produced from the generated implementation will have its content-type overridden to this value.
[§](https://api.rocket.rs/v0.5/rocket/derive.Responder#generics)
Generics
-------------------------------------------------------------------------
The derive accepts any number of type generics and at most one lifetime generic. If a type generic is present and the generic is used in the first field of a structure, the generated implementation will require a bound of `Responder<'r, 'o>` for the field type containing the generic. In all other fields, unless ignores, a bound of `Into` is added.
For example, for a struct `struct Foo(Json, H)`, the derive adds:
* `Json: Responder<'r, 'o>`
* `H: Into>`
use rocket::serde::Serialize;
use rocket::serde::json::Json;
use rocket::http::ContentType;
use rocket::response::Responder;
// The bound `T: Responder` will be added.
#[derive(Responder)]
#[response(status = 404, content_type = "html")]
struct NotFoundHtml(T);
// The bound `Json: Responder` will be added.
#[derive(Responder)]
struct NotFoundJson(Json);
// The bounds `Json: Responder, E: Responder` will be added.
#[derive(Responder)]
enum MyResult {
Ok(Json),
#[response(status = 404)]
Err(E, ContentType)
}
If a lifetime generic is present, it will be replaced with `'o` in the generated implementation `impl Responder<'r, 'o>`:
// Generates `impl<'r, 'o> Responder<'r, 'o> for NotFoundHtmlString<'o>`.
#[derive(Responder)]
#[response(status = 404, content_type = "html")]
struct NotFoundHtmlString<'a>(&'a str);
Both type generics and lifetime generic may be used:
#[derive(Responder)]
struct SomeResult<'o, T>(Result);
---
# FromFormField in rocket::form - Rust
[FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#)
-----------------------------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
::[form](https://api.rocket.rs/v0.5/rocket/form/index.html)
Trait FromFormField Copy item path
==================================
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#182-208)
pub trait FromFormField<'v>: Send + Sized {
// Provided methods
fn from_value(field: ValueField<'v>) -> Result<'v, Self> { ... }
fn from_data<'life0, 'async_trait>(
field: DataField<'v, 'life0>,
) -> Pin> + Send + 'async_trait>>
where Self: 'async_trait,
'v: 'async_trait,
'life0: 'async_trait { ... }
fn default() -> Option { ... }
}
Expand description
Implied form guard ([`FromForm`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
) for parsing a single form field.
Types that implement `FromFormField` automatically implement [`FromForm`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
via a blanket implementation. As such, all `FromFormField` types are form guards and can appear as the type of values in derived `FromForm` struct fields:
#[derive(FromForm)]
struct Person<'r> {
name: &'r str,
age: u16
}
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#semantics)
Semantics
-----------------------------------------------------------------------------------
The implementation of `FromForm` for a `T: FromFormField` type operates as follows:
* When parsing is **strict**, the parser accepts the _first_ value or data field with the corresponding field name and calls `T::from_value()` or `T::from_data()` with the field’s value, respectively. If more than one field value is seen, an \[`ErrorKind::Duplicate`) is emitted. If no matching field is seen, an [`ErrorKind::Missing`](https://api.rocket.rs/v0.5/rocket/form/error/enum.ErrorKind.html#variant.Missing "variant rocket::form::error::ErrorKind::Missing")\
is emitted. Otherwise, the result from the call is emitted.\
\
* When parsing is **lenient**, the parser accepts the first _expected_ value or data field with the corresponding field name and calls `T::from_value()` or `T::from_data()` with the field’s value, respectively. Unexpected values, identified by returning an [`ErrorKind::Unexpected`](https://api.rocket.rs/v0.5/rocket/form/error/enum.ErrorKind.html#variant.Unexpected "variant rocket::form::error::ErrorKind::Unexpected")\
from `from_value()` or `from_data()` are ignored. Any additional fields with a matching field name are ignored. If no matching field is seen and `T` has a default, it is used, otherwise an [`ErrorKind::Missing`](https://api.rocket.rs/v0.5/rocket/form/error/enum.ErrorKind.html#variant.Missing "variant rocket::form::error::ErrorKind::Missing")\
is emitted.\
\
\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#deriving)\
Deriving\
---------------------------------------------------------------------------------\
\
`FromFormField` can be derived for C-like enums, where the generated implementation case-insensitively parses fields with values equal to the name of the variant or the value in `field()`.\
\
/// Fields with value `"simple"` parse as `Kind::Simple`. Fields with value\
/// `"fancy"` parse as `Kind::SoFancy`.\
#[derive(FromFormField)]\
enum Kind {\
Simple,\
#[field(value = "fancy")]\
SoFancy,\
}\
\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#provided-implementations)\
Provided Implementations\
-----------------------------------------------------------------------------------------------------------------\
\
See [`FromForm`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#provided-implementations "trait rocket::form::FromForm")\
for a list of all form guards, including those implemented via `FromFormField`.\
\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#implementing)\
Implementing\
-----------------------------------------------------------------------------------------\
\
Implementing `FromFormField` requires implementing one or both of `from_value` or `from_data`, depending on whether the type can be parsed from a value field (text) and/or streaming binary data. Typically, a value can be parsed from either, either directly or by using request-local cache as an intermediary, and parsing from both should be preferred when sensible.\
\
`FromFormField` is an async trait, so implementations must be decorated with an attribute of `#[rocket::async_trait]`:\
\
use rocket::form::{self, FromFormField, DataField, ValueField};\
\
#[rocket::async_trait]\
impl<'r> FromFormField<'r> for MyType {\
fn from_value(field: ValueField<'r>) -> form::Result<'r, Self> {\
todo!("parse from a value or use default impl")\
}\
\
async fn from_data(field: DataField<'r, '_>) -> form::Result<'r, Self> {\
todo!("parse from a value or use default impl")\
}\
}\
\
### [§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#example)\
Example\
\
The following example parses a custom `Person` type with the format `$name:$data`, where `$name` is expected to be string and `data` is expected to be any slice of bytes.\
\
use rocket::data::ToByteUnit;\
use rocket::form::{self, FromFormField, DataField, ValueField};\
\
use memchr::memchr;\
\
struct Person<'r> {\
name: &'r str,\
data: &'r [u8]\
}\
\
#[rocket::async_trait]\
impl<'r> FromFormField<'r> for Person<'r> {\
fn from_value(field: ValueField<'r>) -> form::Result<'r, Self> {\
match field.value.find(':') {\
Some(i) => Ok(Person {\
name: &field.value[..i],\
data: field.value[(i + 1)..].as_bytes()\
}),\
None => Err(form::Error::validation("does not contain ':'"))?\
}\
}\
\
async fn from_data(field: DataField<'r, '_>) -> form::Result<'r, Self> {\
// Retrieve the configured data limit or use `256KiB` as default.\
let limit = field.request.limits()\
.get("person")\
.unwrap_or(256.kibibytes());\
\
// Read the capped data stream, returning a limit error as needed.\
let bytes = field.data.open(limit).into_bytes().await?;\
if !bytes.is_complete() {\
Err((None, Some(limit)))?;\
}\
\
// Store the bytes in request-local cache and split at ':'.\
let bytes = bytes.into_inner();\
let bytes = rocket::request::local_cache!(field.request, bytes);\
let (raw_name, data) = match memchr(b':', bytes) {\
Some(i) => (&bytes[..i], &bytes[(i + 1)..]),\
None => Err(form::Error::validation("does not contain ':'"))?\
};\
\
// Try to parse the name as UTF-8 or return an error if it fails.\
let name = std::str::from_utf8(raw_name)?;\
Ok(Person { name, data })\
}\
}\
\
use rocket::form::{Form, FromForm};\
\
// The type can be used directly, if only one field is expected...\
#[post("/person", data = "")]\
fn person(person: Form>) { /* ... */ }\
\
// ...or as a named field in another form guard...\
#[derive(FromForm)]\
struct NewPerson<'r> {\
person: Person<'r>\
}\
\
#[post("/person", data = "")]\
fn new_person(person: Form>) { /* ... */ }\
\
Provided Methods[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#provided-methods)\
\
-------------------------------------------------------------------------------------------------\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#187-189)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
Parse a value of `T` from a form value field.\
\
The default implementation returns an error of [`ValueField::unexpected()`](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html#method.unexpected "method rocket::form::ValueField::unexpected")\
.\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#195-197)\
\
#### fn [from\_data](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_data)\
<'life0, 'async\_trait>( field: [DataField](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")\
<'v, 'life0>, ) -> [Pin](https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html "struct core::pin::Pin")\
<[Box](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/boxed/struct.Box.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box")\
> + [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")\
+ 'async\_trait>>\
\
where Self: 'async\_trait, 'v: 'async\_trait, 'life0: 'async\_trait,\
\
Parse a value of `T` from a form data field.\
\
The default implementation returns an error of [`DataField::unexpected()`](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html#method.unexpected "method rocket::form::DataField::unexpected")\
.\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#207)\
\
#### fn [default](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default)\
() -> [Option](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/option/enum.Option.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::option::Option")\
\
\
Returns a default value, if any exists, to be used during lenient parsing when the form field is missing.\
\
A return value of `None` means that field is required to exist and parse successfully, always. A return value of `Some(default)` means that `default` should be used when a field is missing.\
\
The default implementation returns `None`.\
\
Dyn Compatibility[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#dyn-compatibility)\
\
---------------------------------------------------------------------------------------------------\
\
This trait is **not** [dyn compatible](https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility)\
.\
\
_In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe._\
\
Implementations on Foreign Types[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#foreign-impls)\
\
--------------------------------------------------------------------------------------------------------------\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#308)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-%26str)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for &'v [str](https://doc.rust-lang.org/nightly/std/primitive.str.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#308)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default-1)\
\
#### fn [default](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default)\
() -> [Option](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/option/enum.Option.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::option::Option")\
\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#308)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-1)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(f: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#308)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_data-1)\
\
#### fn [from\_data](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_data)\
<'life0, 'async\_trait>( field: [DataField](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")\
<'v, 'life0>, ) -> [Pin](https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html "struct core::pin::Pin")\
<[Box](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/boxed/struct.Box.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box")\
> + [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")\
+ 'async\_trait>>\
\
where Self: 'async\_trait, 'v: 'async\_trait, 'life0: 'async\_trait,\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#365)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-%26%5Bu8%5D)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for &'v \[[u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)\
\]\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#365)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default-2)\
\
#### fn [default](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default)\
() -> [Option](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/option/enum.Option.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::option::Option")\
\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#365)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-2)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(f: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#365)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_data-2)\
\
#### fn [from\_data](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_data)\
<'life0, 'async\_trait>( field: [DataField](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")\
<'v, 'life0>, ) -> [Pin](https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html "struct core::pin::Pin")\
<[Box](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/boxed/struct.Box.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box")\
> + [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")\
+ 'async\_trait>>\
\
where Self: 'async\_trait, 'v: 'async\_trait, 'life0: 'async\_trait,\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#380)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Cow%3C'v,+str%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Cow](https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html "enum alloc::borrow::Cow")\
<'v, [str](https://doc.rust-lang.org/nightly/std/primitive.str.html)\
\>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#380)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default-3)\
\
#### fn [default](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default)\
() -> [Option](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/option/enum.Option.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::option::Option")\
\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#380)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-3)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(f: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#380)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_data-3)\
\
#### fn [from\_data](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_data)\
<'life0, 'async\_trait>( field: [DataField](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")\
<'v, 'life0>, ) -> [Pin](https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html "struct core::pin::Pin")\
<[Box](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/boxed/struct.Box.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box")\
> + [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")\
+ 'async\_trait>>\
\
where Self: 'async\_trait, 'v: 'async\_trait, 'life0: 'async\_trait,\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-IpAddr)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [IpAddr](https://doc.rust-lang.org/nightly/core/net/ip_addr/enum.IpAddr.html "enum core::net::ip_addr::IpAddr")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-4)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-SocketAddr)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [SocketAddr](https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html "enum core::net::socket_addr::SocketAddr")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-5)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#331-344)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-bool)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [bool](https://doc.rust-lang.org/nightly/std/primitive.bool.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#332-334)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default-4)\
\
#### fn [default](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.default)\
() -> [Option](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/option/enum.Option.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::option::Option")\
\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#336-343)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-6)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-char)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [char](https://doc.rust-lang.org/nightly/std/primitive.char.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-7)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-f32)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [f32](https://doc.rust-lang.org/nightly/std/primitive.f32.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-8)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-f64)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [f64](https://doc.rust-lang.org/nightly/std/primitive.f64.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-9)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-i8)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [i8](https://doc.rust-lang.org/nightly/std/primitive.i8.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-10)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-i16)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [i16](https://doc.rust-lang.org/nightly/std/primitive.i16.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-11)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-i32)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [i32](https://doc.rust-lang.org/nightly/std/primitive.i32.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-12)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-i64)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [i64](https://doc.rust-lang.org/nightly/std/primitive.i64.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-13)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-i128)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [i128](https://doc.rust-lang.org/nightly/std/primitive.i128.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-14)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-isize)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [isize](https://doc.rust-lang.org/nightly/std/primitive.isize.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-15)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-u8)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-16)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-u16)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [u16](https://doc.rust-lang.org/nightly/std/primitive.u16.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-17)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-u32)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [u32](https://doc.rust-lang.org/nightly/std/primitive.u32.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-18)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-u64)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [u64](https://doc.rust-lang.org/nightly/std/primitive.u64.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-19)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-u128)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [u128](https://doc.rust-lang.org/nightly/std/primitive.u128.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-20)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-usize)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [usize](https://doc.rust-lang.org/nightly/std/primitive.usize.html)\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-21)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Ipv4Addr)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Ipv4Addr](https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv4Addr.html "struct core::net::ip_addr::Ipv4Addr")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-22)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Ipv6Addr)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Ipv6Addr](https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv6Addr.html "struct core::net::ip_addr::Ipv6Addr")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-23)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-SocketAddrV4)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [SocketAddrV4](https://doc.rust-lang.org/nightly/core/net/socket_addr/struct.SocketAddrV4.html "struct core::net::socket_addr::SocketAddrV4")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-24)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-SocketAddrV6)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [SocketAddrV6](https://doc.rust-lang.org/nightly/core/net/socket_addr/struct.SocketAddrV6.html "struct core::net::socket_addr::SocketAddrV6")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-25)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#412-419)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Date)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Date](https://docs.rs/time/0.3.44/time/date/struct.Date.html "struct time::date::Date")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#413-418)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-26)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#431-439)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-PrimitiveDateTime)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [PrimitiveDateTime](https://docs.rs/time/0.3.44/time/primitive_date_time/struct.PrimitiveDateTime.html "struct time::primitive_date_time::PrimitiveDateTime")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#432-438)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-27)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#421-429)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Time)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Time](https://docs.rs/time/0.3.44/time/time/struct.Time.html "struct time::time::Time")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#422-428)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-28)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Ci8%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroI8](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroI8.html "type core::num::nonzero::NonZeroI8")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-29)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Ci16%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroI16](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroI16.html "type core::num::nonzero::NonZeroI16")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-30)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Ci32%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroI32](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroI32.html "type core::num::nonzero::NonZeroI32")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-31)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Ci64%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroI64](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroI64.html "type core::num::nonzero::NonZeroI64")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-32)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Ci128%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroI128](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroI128.html "type core::num::nonzero::NonZeroI128")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-33)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Cisize%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroIsize](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroIsize.html "type core::num::nonzero::NonZeroIsize")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-34)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Cu8%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroU8](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroU8.html "type core::num::nonzero::NonZeroU8")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-35)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Cu16%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroU16](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroU16.html "type core::num::nonzero::NonZeroU16")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-36)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Cu32%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroU32](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroU32.html "type core::num::nonzero::NonZeroU32")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-37)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Cu64%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroU64](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroU64.html "type core::num::nonzero::NonZeroU64")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-38)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Cu128%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroU128](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroU128.html "type core::num::nonzero::NonZeroU128")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-39)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-NonZero%3Cusize%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [NonZeroUsize](https://doc.rust-lang.org/nightly/core/num/nonzero/type.NonZeroUsize.html "type core::num::nonzero::NonZeroUsize")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#393-401)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value-40)\
\
#### fn [from\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#method.from_value)\
(field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")\
<'v>) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")\
<'v, Self>\
\
Implementors[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#implementors)\
\
-----------------------------------------------------------------------------------------\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/fs/temp_file.rs.html#551)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-TempFile%3C'v%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [TempFile](https://api.rocket.rs/v0.5/rocket/fs/enum.TempFile.html "enum rocket::fs::TempFile")\
<'v>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#290-306)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Capped%3C%26str%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Capped](https://api.rocket.rs/v0.5/rocket/data/struct.Capped.html "struct rocket::data::Capped")\
<&'v [str](https://doc.rust-lang.org/nightly/std/primitive.str.html)\
\>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#347-363)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Capped%3C%26%5Bu8%5D%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Capped](https://api.rocket.rs/v0.5/rocket/data/struct.Capped.html "struct rocket::data::Capped")\
<&'v \[[u8](https://doc.rust-lang.org/nightly/std/primitive.u8.html)\
\]>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/fs/temp_file.rs.html#518-529)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Capped%3CTempFile%3C'v%3E%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Capped](https://api.rocket.rs/v0.5/rocket/data/struct.Capped.html "struct rocket::data::Capped")\
<[TempFile](https://api.rocket.rs/v0.5/rocket/fs/enum.TempFile.html "enum rocket::fs::TempFile")\
<'v>>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#368-378)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Capped%3CCow%3C'v,+str%3E%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Capped](https://api.rocket.rs/v0.5/rocket/data/struct.Capped.html "struct rocket::data::Capped")\
<[Cow](https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html "enum alloc::borrow::Cow")\
<'v, [str](https://doc.rust-lang.org/nightly/std/primitive.str.html)\
\>>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#311-327)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Capped%3CString%3E)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Capped](https://api.rocket.rs/v0.5/rocket/data/struct.Capped.html "struct rocket::data::Capped")\
<[String](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/string/struct.String.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::string::String")\
\>\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form_field.rs.html#329)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-String)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [String](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/string/struct.String.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::string::String")\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/serde/uuid.rs.html#99-104)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Uuid)\
\
### impl<'v> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Uuid](https://api.rocket.rs/v0.5/rocket/serde/uuid/struct.Uuid.html "struct rocket::serde::uuid::Uuid")\
\
Available on **crate feature `uuid`** only.\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/serde/json.rs.html#288-296)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-Json%3CT%3E)\
\
### impl<'v, T: [Deserialize](https://api.rocket.rs/v0.5/rocket/serde/trait.Deserialize.html "trait rocket::serde::Deserialize")\
<'v> + [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")\
\> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [Json](https://api.rocket.rs/v0.5/rocket/serde/json/struct.Json.html "struct rocket::serde::json::Json")\
\
\
Available on **crate feature `json`** only.\
\
[Source](https://api.rocket.rs/v0.5/src/rocket/serde/msgpack.rs.html#202-215)\
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField#impl-FromFormField%3C'v%3E-for-MsgPack%3CT%3E)\
\
### impl<'v, T: [Deserialize](https://api.rocket.rs/v0.5/rocket/serde/trait.Deserialize.html "trait rocket::serde::Deserialize")\
<'v> + [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")\
\> [FromFormField](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")\
<'v> for [MsgPack](https://api.rocket.rs/v0.5/rocket/serde/msgpack/struct.MsgPack.html "struct rocket::serde::msgpack::MsgPack")\
\
\
Available on **crate feature `msgpack`** only.
---
# FromForm in rocket::form - Rust
[FromForm](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#)
-------------------------------------------------------------------
[rocket](https://api.rocket.rs/v0.5/rocket/index.html)
::[form](https://api.rocket.rs/v0.5/rocket/form/index.html)
Trait FromForm Copy item path
=============================
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#532-564)
pub trait FromForm<'r>: Send + Sized {
type Context: Send;
// Required methods
fn init(opts: Options) -> Self::Context;
fn push_value(ctxt: &mut Self::Context, field: ValueField<'r>);
fn push_data<'life0, 'life1, 'async_trait>(
ctxt: &'life0 mut Self::Context,
field: DataField<'r, 'life1>,
) -> Pin + Send + 'async_trait>>
where Self: 'async_trait,
'r: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn finalize(ctxt: Self::Context) -> Result<'r, Self>;
// Provided methods
fn push_error(_ctxt: &mut Self::Context, _error: Error<'r>) { ... }
fn default(opts: Options) -> Option { ... }
}
Expand description
Trait implemented by form guards: types parseable from HTTP forms.
Only form guards that are _collections_, that is, collect more than one form field while parsing, should implement `FromForm`. All other types should implement [`FromFormField`](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")
instead, which offers a simplified interface to parsing a single form field.
For a gentle introduction to forms in Rocket, see the [forms guide](https://rocket.rs/v0.5/guide/requests/#forms)
.
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#form-guards)
Form Guards
----------------------------------------------------------------------------------
A form guard is a guard that operates on form fields, typically those with a particular name prefix. Form guards validate and parse form field data via implementations of `FromForm`. In other words, a type is a form guard _iff_ it implements `FromForm`.
Form guards are used as the inner type of the [`Form`](https://api.rocket.rs/v0.5/rocket/form/struct.Form.html "struct rocket::form::Form")
data guard:
use rocket::form::Form;
#[post("/submit", data = "")]
fn submit(var: Form) { /* ... */ }
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#deriving)
Deriving
----------------------------------------------------------------------------
This trait can, and largely _should_, be automatically derived. When deriving `FromForm`, every field in the structure must implement [`FromForm`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
. Form fields with the struct field’s name are [shifted](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html#method.shift "method rocket::form::name::NameView::shift")
and then pushed to the struct field’s `FromForm` parser.
use rocket::form::FromForm;
#[derive(FromForm)]
struct TodoTask<'r> {
#[field(validate = len(1..))]
description: &'r str,
#[field(name = "done")]
completed: bool
}
For full details on deriving `FromForm`, see the [`FromForm` derive](https://api.rocket.rs/v0.5/rocket/derive.FromForm.html "derive rocket::FromForm")
.
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#parsing-strategy)
Parsing Strategy
--------------------------------------------------------------------------------------------
Form parsing is either _strict_ or _lenient_, controlled by [`Options::strict`](https://api.rocket.rs/v0.5/rocket/form/struct.Options.html#structfield.strict "field rocket::form::Options::strict")
. A _strict_ parse errors when there are missing or extra fields, while a _lenient_ parse allows both, providing there is a [`default()`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#method.default "associated function rocket::form::FromForm::default")
in the case of a missing field.
Most type inherit their strategy on [`FromForm::init()`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#tymethod.init "associated function rocket::form::FromForm::init")
, but some types like `Option` override the requested strategy. The strategy can also be overwritten manually, per-field or per-value, by using the [`Strict`](https://api.rocket.rs/v0.5/rocket/form/struct.Strict.html "struct rocket::form::Strict")
or [`Lenient`](https://api.rocket.rs/v0.5/rocket/form/struct.Lenient.html "struct rocket::form::Lenient")
form guard:
use rocket::form::{self, FromForm, Strict, Lenient};
#[derive(FromForm)]
struct TodoTask<'r> {
strict_bool: Strict,
lenient_inner_option: Option>,
strict_inner_result: form::Result<'r, Strict>,
}
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#defaults)
Defaults
----------------------------------------------------------------------------
A form guard may have a _default_ which is used in case of a missing field when parsing is _lenient_. When parsing is strict, all errors, including missing fields, are propagated directly.
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#provided-implementations)
Provided Implementations
------------------------------------------------------------------------------------------------------------
Rocket implements `FromForm` for many common types. As a result, most applications will never need a custom implementation of `FromForm` or `FromFormField`. Their behavior is documented in the table below.
| Type | Strategy | Default | Data | Value | Notes |
| --- | --- | --- | --- | --- | --- |
| [`Strict`](https://api.rocket.rs/v0.5/rocket/form/struct.Strict.html "struct rocket::form::Strict") | **strict** | if `strict` `T` | if `T` | if `T` | `T: FromForm` |
| [`Lenient`](https://api.rocket.rs/v0.5/rocket/form/struct.Lenient.html "struct rocket::form::Lenient") | **lenient** | if `lenient` `T` | if `T` | if `T` | `T: FromForm` |
| `Option` | **strict** | `None` | if `T` | if `T` | Infallible, `T: FromForm` |
| [`Result`](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result") | _inherit_ | `T::finalize()` | if `T` | if `T` | Infallible, `T: FromForm` |
| `Vec` | _inherit_ | `vec![]` | if `T` | if `T` | `T: FromForm` |
| [`HashMap`](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/collections/struct.HashMap.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::collections::HashMap") | _inherit_ | `HashMap::new()` | if `V` | if `V` | `K: FromForm + Eq + Hash`, `V: FromForm` |
| [`BTreeMap`](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/collections/struct.BTreeMap.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::collections::BTreeMap") | _inherit_ | `BTreeMap::new()` | if `V` | if `V` | `K: FromForm + Ord`, `V: FromForm` |
| [`Range`](https://doc.rust-lang.org/stable/std/ops/struct.Range.html) | _inherit_ | **no default** | if `T` | if `T` | `T: FromForm`, expects `start`, `end` fields |
| [`RangeFrom`](https://doc.rust-lang.org/stable/std/ops/struct.RangeFrom.html) | _inherit_ | **no default** | if `T` | if `T` | `T: FromForm`, expects `start` field |
| [`RangeTo`](https://doc.rust-lang.org/stable/std/ops/struct.RangeTo.html) | _inherit_ | **no default** | if `T` | if `T` | `T: FromForm`, expects `end` field |
| [`RangeToInclusive`](https://doc.rust-lang.org/stable/std/ops/struct.RangeToInclusive.html) | _inherit_ | **no default** | if `T` | if `T` | `T: FromForm`, expects `end` field |
| `bool` | _inherit_ | `false` | No | Yes | `"yes"/"on"/"true"`, `"no"/"off"/"false"` |
| (un)signed int | _inherit_ | **no default** | No | Yes | `{u,i}{size,8,16,32,64,128}` |
| _nonzero_ int | _inherit_ | **no default** | No | Yes | `NonZero{I,U}{size,8,16,32,64,128}` |
| float | _inherit_ | **no default** | No | Yes | `f{32,64}` |
| `&str` | _inherit_ | **no default** | Yes | Yes | Percent-decoded. Data limit `string` applies. |
| `&[u8]` | _inherit_ | **no default** | Yes | Yes | Raw bytes. Data limit `bytes` applies. |
| `String` | _inherit_ | **no default** | Yes | Yes | Exactly `&str`, but owned. Prefer `&str`. |
| IP Address | _inherit_ | **no default** | No | Yes | [`IpAddr`](https://doc.rust-lang.org/nightly/core/net/ip_addr/enum.IpAddr.html "enum core::net::ip_addr::IpAddr")
, [`Ipv4Addr`](https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv4Addr.html "struct core::net::ip_addr::Ipv4Addr")
, [`Ipv6Addr`](https://doc.rust-lang.org/nightly/core/net/ip_addr/struct.Ipv6Addr.html "struct core::net::ip_addr::Ipv6Addr") |
| Socket Address | _inherit_ | **no default** | No | Yes | [`SocketAddr`](https://doc.rust-lang.org/nightly/core/net/socket_addr/enum.SocketAddr.html "enum core::net::socket_addr::SocketAddr")
, [`SocketAddrV4`](https://doc.rust-lang.org/nightly/core/net/socket_addr/struct.SocketAddrV4.html "struct core::net::socket_addr::SocketAddrV4")
, [`SocketAddrV6`](https://doc.rust-lang.org/nightly/core/net/socket_addr/struct.SocketAddrV6.html "struct core::net::socket_addr::SocketAddrV6") |
| [`TempFile`](https://api.rocket.rs/v0.5/rocket/fs/enum.TempFile.html "enum rocket::fs::TempFile") | _inherit_ | **no default** | Yes | Yes | Data limits apply. See [`TempFile`](https://api.rocket.rs/v0.5/rocket/fs/enum.TempFile.html "enum rocket::fs::TempFile")
. |
| [`Capped`](https://api.rocket.rs/v0.5/rocket/data/struct.Capped.html "struct rocket::data::Capped") | _inherit_ | **no default** | Yes | Yes | `C` is `&str`, `String`, `&[u8]` or `TempFile`. |
| [`time::Date`](https://docs.rs/time/0.3.44/time/date/struct.Date.html "struct time::date::Date") | _inherit_ | **no default** | No | Yes | `%F` (`YYYY-MM-DD`). HTML “date” input. |
| [`time::DateTime`](https://docs.rs/time/0.3.44/time/primitive_date_time/struct.PrimitiveDateTime.html "struct time::primitive_date_time::PrimitiveDateTime") | _inherit_ | **no default** | No | Yes | `%FT%R` or `%FT%T` (`YYYY-MM-DDTHH:MM[:SS]`) |
| [`time::Time`](https://docs.rs/time/0.3.44/time/time/struct.Time.html "struct time::time::Time") | _inherit_ | **no default** | No | Yes | `%R` or `%T` (`HH:MM[:SS]`) |
### [§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#additional-notes)
Additional Notes
* **`Vec` where `T: FromForm`**
Parses a sequence of `T`’s. A new `T` is created whenever the field name’s key changes or is empty; the previous `T` is finalized and errors are stored. While the key remains the same and non-empty, form values are pushed to the current `T` after being shifted. All collected errors are returned at finalization, if any, or the successfully created vector is returned.
* **`HashMap` where `K: FromForm + Eq + Hash`, `V: FromForm`**
**`BTreeMap` where `K: FromForm + Ord`, `V: FromForm`**
Parses a sequence of `(K, V)`’s. A new pair is created for every unique first index of the key.
If the key has only one index (`map[index]=value`), the index itself is pushed to `K`’s parser and the remaining shifted field is pushed to `V`’s parser.
If the key has two indices (`map[k:index]=value` or `map[v:index]=value`), the first index must start with `k` or `v`. If the first index starts with `k`, the shifted field is pushed to `K`’s parser. If the first index starts with `v`, the shifted field is pushed to `V`’s parser. If the first index is anything else, an error is created for the offending form field.
Errors are collected as they occur. Finalization finalizes all pairs and returns errors, if any, or the map.
* **`bool`**
Parses as `false` for missing values (when lenient) and case-insensitive values of `off`, `false`, and `no`. Parses as `true` for values of `on`, `true`, `yes`, and the empty value. Failed to parse otherwise.
* **[`time::DateTime`](https://docs.rs/time/0.3.44/time/primitive_date_time/struct.PrimitiveDateTime.html "struct time::primitive_date_time::PrimitiveDateTime")
**
Parses a date in `%FT%R` or `%FT%T` format, that is, `YYYY-MM-DDTHH:MM` or `YYYY-MM-DDTHH:MM:SS`. This is the `"datetime-local"` HTML input type without support for the millisecond variant.
* **[`time::Time`](https://docs.rs/time/0.3.44/time/time/struct.Time.html "struct time::time::Time")
**
Parses a time in `%R` or `%T` format, that is, `HH:MM` or `HH:MM:SS`. This is the `"time"` HTML input type without support for the millisecond variant.
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#push-parsing)
Push Parsing
------------------------------------------------------------------------------------
`FromForm` describes a push-based parser for Rocket’s [field wire format](https://api.rocket.rs/v0.5/rocket/form/index.html#field-wire-format "mod rocket::form")
. Fields are preprocessed into either [`ValueField`](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")
s or [`DataField`](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")
s which are then pushed to the parser in [`FromForm::push_value()`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#tymethod.push_value "associated function rocket::form::FromForm::push_value")
or [`FromForm::push_data()`](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#tymethod.push_data "associated function rocket::form::FromForm::push_data")
, respectively. Both url-encoded forms and multipart forms are supported. All url-encoded form fields are preprocessed as [`ValueField`](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")
s. Multipart form fields with Content-Types are processed as [`DataField`](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")
s while those without a set Content-Type are processed as [`ValueField`](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")
s. `ValueField` field names and values are percent-decoded.
Parsing is split into 3 stages. After preprocessing, the three stages are:
1. **Initialization.** The type sets up a context for later `push`es.
use rocket::form::Options;
fn init(opts: Options) -> Self::Context {
todo!("return a context for storing parse state")
}
2. **Push.** The structure is repeatedly pushed form fields; the latest context is provided with each `push`. If the structure contains children, it uses the first [`key()`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html#method.key "method rocket::form::name::NameView::key")
to identify a child to which it then `push`es the remaining `field` to, likely with a [`shift()`ed](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html#method.shift "method rocket::form::name::NameView::shift")
name. Otherwise, the structure parses the `value` itself. The context is updated as needed.
use rocket::form::{ValueField, DataField};
fn push_value(ctxt: &mut Self::Context, field: ValueField<'r>) {
todo!("modify context as necessary for `field`")
}
async fn push_data(ctxt: &mut Self::Context, field: DataField<'r, '_>) {
todo!("modify context as necessary for `field`")
}
3. **Finalization.** The structure is informed that there are no further fields. It systemizes the effects of previous `push`es via its context to return a parsed structure or generate [`Errors`](https://api.rocket.rs/v0.5/rocket/form/struct.Errors.html "struct rocket::form::Errors")
.
use rocket::form::Result;
fn finalize(ctxt: Self::Context) -> Result<'r, Self> {
todo!("inspect context to generate `Self` or `Errors`")
}
These three stages make up the entirety of the `FromForm` trait.
### [§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#nesting-and-nameview)
Nesting and [`NameView`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html "struct rocket::form::name::NameView")
Each field name key typically identifies a unique child of a structure. As such, when processed left-to-right, the keys of a field jointly identify a unique leaf of a structure. The value of the field typically represents the desired value of the leaf.
A [`NameView`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html "struct rocket::form::name::NameView")
captures and simplifies this “left-to-right” processing of a field’s name by exposing a sliding-prefix view into a name. A [`shift()`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html#method.shift "method rocket::form::name::NameView::shift")
shifts the view one key to the right. Thus, a `Name` of `a.b.c` when viewed through a new [`NameView`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html "struct rocket::form::name::NameView")
is `a`. Shifted once, the view is `a.b`. [`key()`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html#method.key "method rocket::form::name::NameView::key")
returns the last (or “current”) key in the view. A nested structure can thus handle a field with a `NameView`, operate on the [`key()`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html#method.key "method rocket::form::name::NameView::key")
, [`shift()`](https://api.rocket.rs/v0.5/rocket/form/name/struct.NameView.html#method.shift "method rocket::form::name::NameView::shift")
the `NameView`, and pass the field with the shifted `NameView` to the next processor which handles `b` and so on.
### [§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#a-simple-example)
A Simple Example
The following example uses `f1=v1&f2=v2` to illustrate field/value pairs `(f1, v2)` and `(f2, v2)`. This is the same encoding used to send HTML forms over HTTP, though Rocket’s push-parsers are unaware of any specific encoding, dealing only with logical `field`s, `index`es, and `value`s.
#### [§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#a-single-field-t-formformfield)
A Single Field (`T: FormFormField`)
The simplest example parses a single value of type `T` from a string with an optional default value: this is `impl FromForm for T`:
1. **Initialization.** The context stores form options and an `Option` of `Result` for storing the `result` of parsing `T`, which is initially set to `None`.
use rocket::form::{self, FromFormField};
struct Context<'r, T: FromFormField<'r>> {
opts: form::Options,
result: Option>,
}
fn init(opts: form::Options) -> Context<'r, T> {
Context { opts, result: None }
}
2. **Push.** If `ctxt.result` is `None`, `T` is parsed from `field`, and the result is stored in `context.result`. Otherwise a field has already been parsed and nothing is done.
fn push_value(ctxt: &mut Context<'r, T>, field: ValueField<'r>) {
if ctxt.result.is_none() {
ctxt.result = Some(T::from_value(field));
}
}
3. **Finalization.** If `ctxt.result` is `None`, parsing is lenient, and `T` has a default, the default is returned. Otherwise a `Missing` error is returned. If `ctxt.result` is `Some(v)`, the result `v` is returned.
fn finalize(ctxt: Context<'r, T>) -> form::Result<'r, T> {
match ctxt.result {
Some(result) => result,
None if ctxt.opts.strict => Err(Errors::from(ErrorKind::Missing)),
None => match T::default() {
Some(default) => Ok(default),
None => Err(Errors::from(ErrorKind::Missing)),
}
}
}
This implementation is complete except for the following details:
* handling both `push_data` and `push_value`
* checking for duplicate pushes when parsing is `strict`
* tracking the field’s name and value to generate a complete [`Error`](https://api.rocket.rs/v0.5/rocket/form/struct.Error.html "struct rocket::form::Error")
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#implementing)
Implementing
------------------------------------------------------------------------------------
Implementing `FromForm` should be a rare occurrence. Prefer instead to use Rocket’s built-in derivation or, for custom types, implementing [`FromFormField`](https://api.rocket.rs/v0.5/rocket/form/trait.FromFormField.html "trait rocket::form::FromFormField")
.
An implementation of `FromForm` consists of implementing the three stages outlined above. `FromForm` is an async trait, so implementations must be decorated with an attribute of `#[rocket::async_trait]`:
use rocket::form::{self, FromForm, DataField, ValueField};
#[rocket::async_trait]
impl<'r> FromForm<'r> for MyType {
type Context = MyContext;
fn init(opts: form::Options) -> Self::Context {
todo!()
}
fn push_value(ctxt: &mut Self::Context, field: ValueField<'r>) {
todo!()
}
async fn push_data(ctxt: &mut Self::Context, field: DataField<'r, '_>) {
todo!()
}
fn finalize(this: Self::Context) -> form::Result<'r, Self> {
todo!()
}
}
The lifetime `'r` corresponds to the lifetime of the request.
### [§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#a-more-involved-example)
A More Involved Example
We illustrate implementation of `FromForm` through an example. The example implements `FromForm` for a `Pair(A, B)` type where `A: FromForm` and `B: FromForm`, parseable from forms with at least two fields, one with a key of `0` and the other with a key of `1`. The field with key `0` is parsed as an `A` while the field with key `1` is parsed as a `B`. Specifically, to parse a `Pair(A, B)` from a field with prefix `pair`, a form with the following fields must be submitted:
* `pair[0]` - type A
* `pair[1]` - type B
Examples include:
* `pair[0]=id&pair[1]=100` as `Pair(&str, usize)`
* `pair[0]=id&pair[1]=100` as `Pair(&str, &str)`
* `pair[0]=2012-10-12&pair[1]=100` as `Pair(time::Date, &str)`
* `pair.0=2012-10-12&pair.1=100` as `Pair(time::Date, usize)`
use either::Either;
use rocket::form::{self, FromForm, ValueField, DataField, Error, Errors};
/// A form guard parseable from fields `.0` and `.1`.
struct Pair(A, B);
// The parsing context. We'll be pushing fields with key `.0` to `left`
// and fields with `.1` to `right`. We'll collect errors along the way.
struct PairContext<'v, A: FromForm<'v>, B: FromForm<'v>> {
left: A::Context,
right: B::Context,
errors: Errors<'v>,
}
#[rocket::async_trait]
impl<'v, A: FromForm<'v>, B: FromForm<'v>> FromForm<'v> for Pair {
type Context = PairContext<'v, A, B>;
// We initialize the `PairContext` as expected.
fn init(opts: form::Options) -> Self::Context {
PairContext {
left: A::init(opts),
right: B::init(opts),
errors: Errors::new()
}
}
// For each value, we determine if the key is `.0` (left) or `.1`
// (right) and push to the appropriate parser. If it was neither, we
// store the error for emission on finalization. The parsers for `A` and
// `B` will handle duplicate values and so on.
fn push_value(ctxt: &mut Self::Context, field: ValueField<'v>) {
match ctxt.context(field.name) {
Ok(Either::Left(ctxt)) => A::push_value(ctxt, field.shift()),
Ok(Either::Right(ctxt)) => B::push_value(ctxt, field.shift()),
Err(e) => ctxt.errors.push(e),
}
}
// This is identical to `push_value` but for data fields.
async fn push_data(ctxt: &mut Self::Context, field: DataField<'v, '_>) {
match ctxt.context(field.name) {
Ok(Either::Left(ctxt)) => A::push_data(ctxt, field.shift()).await,
Ok(Either::Right(ctxt)) => B::push_data(ctxt, field.shift()).await,
Err(e) => ctxt.errors.push(e),
}
}
// Finally, we finalize `A` and `B`. If both returned `Ok` and we
// encountered no errors during the push phase, we return our pair. If
// there were errors, we return them. If `A` and/or `B` failed, we
// return the commutative errors.
fn finalize(mut ctxt: Self::Context) -> form::Result<'v, Self> {
match (A::finalize(ctxt.left), B::finalize(ctxt.right)) {
(Ok(l), Ok(r)) if ctxt.errors.is_empty() => Ok(Pair(l, r)),
(Ok(_), Ok(_)) => Err(ctxt.errors),
(left, right) => {
if let Err(e) = left { ctxt.errors.extend(e); }
if let Err(e) = right { ctxt.errors.extend(e); }
Err(ctxt.errors)
}
}
}
}
impl<'v, A: FromForm<'v>, B: FromForm<'v>> PairContext<'v, A, B> {
// Helper method used by `push_{value, data}`. Determines which context
// we should push to based on the field name's key. If the key is
// neither `0` nor `1`, we return an error.
fn context(
&mut self,
name: form::name::NameView<'v>
) -> Result, Error<'v>> {
use std::borrow::Cow;
match name.key().map(|k| k.as_str()) {
Some("0") => Ok(Either::Left(&mut self.left)),
Some("1") => Ok(Either::Right(&mut self.right)),
_ => Err(Error::from(&[Cow::Borrowed("0"), Cow::Borrowed("1")])
.with_entity(form::error::Entity::Index(0))
.with_name(name)),
}
}
}
Required Associated Types[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#required-associated-types)
--------------------------------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#534)
#### type [Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#associatedtype.Context)
: [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")
The form guard’s parsing context.
Required Methods[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#required-methods)
--------------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#537)
#### fn [init](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.init)
(opts: [Options](https://api.rocket.rs/v0.5/rocket/form/struct.Options.html "struct rocket::form::Options")
) -> Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
Initializes and returns the parsing context for `Self`.
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#540)
#### fn [push\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.push_value)
(ctxt: &mut Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
, field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")
<'r>)
Processes the value field `field`.
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#543)
#### fn [push\_data](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.push_data)
<'life0, 'life1, 'async\_trait>( ctxt: &'life0 mut Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
, field: [DataField](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")
<'r, 'life1>, ) -> [Pin](https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html "struct core::pin::Pin")
<[Box](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/boxed/struct.Box.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box")
+ [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")
+ 'async\_trait>>
where Self: 'async\_trait, 'r: 'async\_trait, 'life0: 'async\_trait, 'life1: 'async\_trait,
Processes the data field `field`.
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#552)
#### fn [finalize](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.finalize)
(ctxt: Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")
<'r, Self>
Finalizes parsing. Returns the parsed value when successful or collection of [`Errors`](https://api.rocket.rs/v0.5/rocket/form/struct.Errors.html "struct rocket::form::Errors")
otherwise.
Provided Methods[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#provided-methods)
--------------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#548)
#### fn [push\_error](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#method.push_error)
(\_ctxt: &mut Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
, \_error: [Error](https://api.rocket.rs/v0.5/rocket/form/struct.Error.html "struct rocket::form::Error")
<'r>)
Processes the external form or field error `_error`.
The default implementation does nothing, which is always correct.
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#561-563)
#### fn [default](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#method.default)
(opts: [Options](https://api.rocket.rs/v0.5/rocket/form/struct.Options.html "struct rocket::form::Options")
) -> [Option](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/option/enum.Option.html "enum rocket::mtls::oid::asn1_rs::nom::lib::std::option::Option")
Returns a default value, if any, to use when a value is desired and parsing fails.
The default implementation initializes `Self` with `opts` and finalizes immediately, returning the value if finalization succeeds. This is always correct and should likely not be changed. Returning a different value may result in ambiguous parses.
Dyn Compatibility[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#dyn-compatibility)
----------------------------------------------------------------------------------------------
This trait is **not** [dyn compatible](https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility)
.
_In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe._
Implementations on Foreign Types[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#foreign-impls)
---------------------------------------------------------------------------------------------------------
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#882-920)
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#impl-FromForm%3C'v%3E-for-(A,+B))
### impl<'v, A: [FromForm](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
<'v>, B: [FromForm](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
<'v>> [FromForm](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
<'v> for [(A, B)](https://doc.rust-lang.org/nightly/std/primitive.tuple.html)
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#883)
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#associatedtype.Context-1)
#### type [Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#associatedtype.Context)
= PairContext<'v, A, B>
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#885-891)
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#method.init)
#### fn [init](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.init)
(opts: [Options](https://api.rocket.rs/v0.5/rocket/form/struct.Options.html "struct rocket::form::Options")
) -> Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#893-899)
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#method.push_value)
#### fn [push\_value](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.push_value)
(ctxt: &mut Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
, field: [ValueField](https://api.rocket.rs/v0.5/rocket/form/struct.ValueField.html "struct rocket::form::ValueField")
<'v>)
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#901-907)
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#method.push_data)
#### fn [push\_data](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.push_data)
<'life0, 'life1, 'async\_trait>( ctxt: &'life0 mut Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
, field: [DataField](https://api.rocket.rs/v0.5/rocket/form/struct.DataField.html "struct rocket::form::DataField")
<'v, 'life1>, ) -> [Pin](https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html "struct core::pin::Pin")
<[Box](https://api.rocket.rs/v0.5/rocket/mtls/oid/asn1_rs/nom/lib/std/boxed/struct.Box.html "struct rocket::mtls::oid::asn1_rs::nom::lib::std::boxed::Box")
+ [Send](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html "trait core::marker::Send")
+ 'async\_trait>>
where Self: 'async\_trait, 'v: 'async\_trait, 'life0: 'async\_trait, 'life1: 'async\_trait,
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#909-919)
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#method.finalize)
#### fn [finalize](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#tymethod.finalize)
(ctxt: Self::[Context](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html#associatedtype.Context "type rocket::form::FromForm::Context")
) -> [Result](https://api.rocket.rs/v0.5/rocket/form/type.Result.html "type rocket::form::Result")
<'v, Self>
[Source](https://api.rocket.rs/v0.5/src/rocket/form/from_form.rs.html#923-941)
[§](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm#impl-FromForm%3C'v%3E-for-Arc%3CT%3E)
### impl<'v, T: [FromForm](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
<'v> + [Sync](https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html "trait core::marker::Sync")
\> [FromForm](https://api.rocket.rs/v0.5/rocket/form/trait.FromForm.html "trait rocket::form::FromForm")
<'v> for [Arc](https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html "struct alloc::sync::Arc")