Skip to content

Parsing tuple struct #34

@KeenS

Description

@KeenS

Parsing (1-element) tuple structs into their inner type fail.

#[derive(Deserialize, Serialize, PartialEq, Debug)]
struct UserId(u32);

#[derive(Deserialize, Serialize, PartialEq, Debug)]
struct Query {
    user_id: UserId,
}

fn main() {
    let query = "user_id=1";
    
    println!("{:?}", from_str::<Query>(query));
      // Err(Error { err: "invalid type: string \"1\", expected tuple struct UserId" })
    println!("{:?}", to_string(Query{user_id: UserId(1)}));
      // Ok("user_id=1")
}

I hope it could do. FYI, serde_json can do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions