Struct rocket::config::Limits[][src]

pub struct Limits { /* fields omitted */ }
Expand description

Mapping from data type to size limits.

A Limits structure contains a mapping from a given data type (“forms”, “json”, and so on) to the maximum size in bytes that should be accepted by a Rocket application for that data type. For instance, if the limit for “forms” is set to 256, only 256 bytes from an incoming form request will be read.

Defaults

As documented in config, the default limits are as follows:

  • forms: 32KiB

Usage

A Limits structure is created following the builder pattern:

use rocket::config::Limits;

// Set a limit of 64KiB for forms and 3MiB for JSON.
let limits = Limits::new()
    .limit("forms", 64 * 1024)
    .limit("json", 3 * 1024 * 1024);

Implementations

Construct a new Limits structure with the default limits set.

Example

use rocket::config::Limits;

let limits = Limits::new();
assert_eq!(limits.get("forms"), Some(32 * 1024));

Adds or replaces a limit in self, consuming self and returning a new Limits structure with the added or replaced limit.

Example

use rocket::config::Limits;

let limits = Limits::new()
    .limit("json", 1 * 1024 * 1024);

assert_eq!(limits.get("forms"), Some(32 * 1024));
assert_eq!(limits.get("json"), Some(1 * 1024 * 1024));

let new_limits = limits.limit("json", 64 * 1024 * 1024);
assert_eq!(new_limits.get("json"), Some(64 * 1024 * 1024));

Retrieve the set limit, if any, for the data type with name name.

Example

use rocket::config::Limits;

let limits = Limits::new()
    .limit("json", 64 * 1024 * 1024);

assert_eq!(limits.get("forms"), Some(32 * 1024));
assert_eq!(limits.get("json"), Some(64 * 1024 * 1024));
assert!(limits.get("msgpack").is_none());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts self into a collection.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Get the TypeId of this object.