Skip to content

Support fat enums #131

@Veetaha

Description

@Veetaha

💡 Feature description

It would be cool if we could use fat enum (type unions) as a first-class citizen with dynomite. For example, serde_dynamodb supports this via serde, but I am not sure how we should go about this in dynomite

💻 Basic example

#[derive(Item, Clone)]
struct Shape {
    #[dynomite(partition_key)]
    id: Uuid,
    display_name: String,
    #[dynomite(flatten)]
    kind: ShapeKind,
}

#[derive(Attributes)]
#[dynomite(tag = "shape_kind")] // tag for internally-tagged enum
enum ShapeKind {
    Square {
        width: u32,
        height: u32,
    }
    Circle {
        radius: u32
    },
}

I would expect it to be represented as:

{
     "id": "8e4a34e5-dcab-4462-9e81-b8181195b69f",
     "display_name": "bruh",
     "shape_kind": "Square",
     "width": 42,
     "height": 65,
}
{
     "id": "8e4a34e5-dcab-4462-9e81-b8181195b69f",
     "display_name": "bruh",
     "shape_kind": "Circle",
     "radius": 43,
}

With a flat structure (so that it is possible to use enum properties as partition/sort keys.

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