Skip to content

Embedded struct support #6

Description

@Kolterdyx

It would be nice to have support for automatically matching fields across embedded structs:

type AuditData struct {
    CreatedAt time.Time
    UpdatedAt time.Time
}

type A struct {
    Name string
    CreatedAt time.Time
    UpdatedAt time.Time
}

type B struct {
    Name string
    AuditData
}

var A2B = convgen.Struct[A, B]() // currently this fails because it doesn't match fields inside embedded structs

I know this can be done manually using convgen.Match, but that has to be on a field by field basis, for every converter. It would be nice if we could have a module option for some embedding level of automatic search:

var mod = convgen.Module(convgen.MatchEmbedded(1)) // Match embedded structs automatically, up to one level

// ...

var A2B = convgen.Struct[A, B]() // Would match A.CreatedAt to B.AuditData.CreatedAt, and so on

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