Struct rocket::form::ValueField[][src]

pub struct ValueField<'r> {
    pub name: NameView<'r>,
    pub value: &'r str,
}
Expand description

A form field with a string value.

Rocket preprocesses all form fields into either ValueFields or DataFields. All fields from url-encoded forms, and fields without Content-Types from multipart forms, are preprocessed as a ValueField.

Fields

name: NameView<'r>

The (decoded) name of the form field.

value: &'r str

The (decoded) value of the form field.

Implementations

impl<'v> ValueField<'v>[src]

pub fn parse(field: &'v str) -> Self[src]

Parse a field string, where both the key and value are assumed to be URL-decoded while preserving the = delimiter, into a ValueField.

This implements 3.2, 3.3 of section 5.1 of the WHATWG living standard.

Example

use rocket::form::ValueField;

let parsed = ValueField::parse("a cat=an A+ pet");
assert_eq!(parsed.name, "a cat");
assert_eq!(parsed.value, "an A+ pet");

let parsed = ValueField::parse("a cat is an A+ pet");
assert_eq!(parsed.name, "a cat is an A+ pet");
assert_eq!(parsed.value, "");

let parsed = ValueField::parse("cat.food=yum?");
assert_eq!(parsed.name, "cat");
assert_eq!(parsed.name.source(), "cat.food");
assert_eq!(parsed.value, "yum?");

pub fn from_value(value: &'v str) -> Self[src]

Create a ValueField from a value, which is assumed to be URL-decoded. The field name will be empty.

This is equivalent to ValueField::from(("", value)). To create a ValueField from both a name and a value, use ValueField::from((name, value)).

Example

use rocket::form::ValueField;

let parsed = ValueField::from_value("A+=kitten");
assert_eq!(parsed.name, "");
assert_eq!(parsed.value, "A+=kitten");

pub fn shift(self) -> Self[src]

Shift the name of self and return self with the shfited name.

See NameView::shift() for the details on name “shifting”.

Example

use rocket::form::ValueField;

let parsed = ValueField::parse("cat.food=yum?");
assert_eq!(parsed.name, "cat");
assert_eq!(parsed.name.source(), "cat.food");
assert_eq!(parsed.name.key_lossy(), "cat");

let shifted = parsed.shift();
assert_eq!(shifted.name, "cat.food");
assert_eq!(shifted.name.key_lossy(), "food");

pub fn unexpected(&self) -> Error<'v>[src]

Creates a complete unexpected value field Error from self.

The error will have the following properties:

Example

use rocket::form::ValueField;
use rocket::form::error::{ErrorKind, Entity};

let field = ValueField::parse("cat.food=yum?");
let error = field.unexpected();

assert_eq!(error.name.as_ref().unwrap(), "cat.food");
assert_eq!(error.value.as_ref().unwrap(), "yum?");
assert_eq!(error.kind, ErrorKind::Unexpected);
assert_eq!(error.entity, Entity::ValueField);

pub fn missing(&self) -> Error<'v>[src]

Creates a complete mising value field Error from self.

The error will have the following properties:

Example

use rocket::form::ValueField;
use rocket::form::error::{ErrorKind, Entity};

let field = ValueField::parse("cat.food=yum?");
let error = field.missing();

assert_eq!(error.name.as_ref().unwrap(), "cat.food");
assert_eq!(error.value.as_ref().unwrap(), "yum?");
assert_eq!(error.kind, ErrorKind::Missing);
assert_eq!(error.entity, Entity::ValueField);

Trait Implementations

impl<'r> Clone for ValueField<'r>[src]

fn clone(&self) -> ValueField<'r>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'r> Debug for ValueField<'r>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<'a> From<(&'a str, &'a str)> for ValueField<'a>[src]

fn from((name, value): (&'a str, &'a str)) -> Self[src]

Performs the conversion.

impl<'a, 'b> PartialEq<ValueField<'b>> for ValueField<'a>[src]

fn eq(&self, other: &ValueField<'b>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

Auto Trait Implementations

impl<'r> RefUnwindSafe for ValueField<'r>

impl<'r> Send for ValueField<'r>

impl<'r> Sync for ValueField<'r>

impl<'r> Unpin for ValueField<'r>

impl<'r> UnwindSafe for ValueField<'r>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> IntoCollection<T> for T

pub fn into_collection<A>(self) -> SmallVec<A> where
    A: Array<Item = T>, 

Converts self into a collection.

pub fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
    F: FnMut(T) -> U,
    A: Array<Item = U>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V