pub struct Limits { /* private fields */ }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
sourceimpl Limits
impl Limits
sourcepub fn new() -> Self
pub fn new() -> Self
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));sourcepub fn limit<S: Into<String>>(self, name: S, limit: u64) -> Self
pub fn limit<S: Into<String>>(self, name: S, limit: u64) -> Self
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));sourcepub fn get(&self, name: &str) -> Option<u64>
pub fn get(&self, name: &str) -> Option<u64>
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
Auto Trait Implementations
impl RefUnwindSafe for Limits
impl Send for Limits
impl Sync for Limits
impl Unpin for Limits
impl UnwindSafe for Limits
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
sourcefn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more