Function rocket_enumform::from_str[][src]

pub fn from_str<'a, T>(string: &'a str) -> Result<T, Error> where
    T: Deserialize<'a>, 
Expand description

Deserialize an instance of type T from a string of UrlEncoded text.

Always use UrlEncoded to deserialize UrlEncoded request data.

Example

use rocket::serde::Deserialize;

#[derive(Debug, PartialEq, Deserialize)]
struct Data<'r> {
    framework: &'r str,
    stars: usize,
}

let string = r#"framework=Rocket&stars=5"#;

let data: Data = rocket_enumform::from_str(string).unwrap();
assert_eq!(data, Data { framework: "Rocket", stars: 5 });

Errors

This conversion can fail if the structure of the input does not match the structure expected by T, for example if T is a struct type but the input contains something other than a UrlEncoded map. It can also fail if the structure is correct but T’s implementation of Deserialize decides that something is wrong with the data, for example required struct fields are missing from the UrlEncoded map or some number is too big to fit in the expected primitive type.