formsrustpostrust-rocket

How to decapsulate a structure data from Form with Rocket in rust


With Rocket library I want to post a struct with an html form.

#[derive(Debug, FromForm, Serialize)]
pub struct MyStructForm {
    pub item1: String,
    pub item2: u32,
}

I managed to get Form in the following code :

#[post("/an/url", data="<input>")]
pub fn post_an_url(input: Form<MyStructForm>)
    -> Result<Json<u32>, String> {

input value is not MyStructForm but Form<MyStructForm>.

Is there a way to "decapsulate" and get MyStructForm data instead ?

    let my_struct = a_function_to_decapsulate_form(input);

Solution

  • You should read the documentation of Form structure. There is several way: