Skip to content

Untagged de/serialisation #37

@ThouCheese

Description

@ThouCheese

In order to do serialisation or deserialisation we will want to support untagged enums.

#[test]
fn test_untagged() {
    #[derive(facet_derive::Facet)]
    #[facet(untagged)]
    enum FreeOfTag {
        TupleVariant(i32),
        StructVariant {
            field: bool,
            friend: Option<Box<FreeOfTag>>,
        },
    }

    let test = facet_peek::Peek::new(&FreeOfTag::TupleVariant(3));
    assert_eq!("3", facet_json::to_json_string(test, false));
    let test2 = facet_peek::Peek::new(&FreeOfTag::StructVariant {
        field: true,
        friend: Some(Box::new(FreeOfTag::TupleVariant(2))),
    });
    assert_eq!(r#"{"field":true,"friend":3}"#, facet_json::to_json_string(test, false));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions