Skip to content

Improve the API for choosing the type of serialization #162

Open
@sindresorhus

Description

@sindresorhus

Current:

extension Foo: Defaults.Serializable, Defaults.PreferRawRepresentable {}

I think this may be better:

extension Foo: Defaults.Serializable.RawRepresentable {}

This is shorter, but more importantly, it makes the choice explicit. Users should prefer this over Defaults.Serializable. Defaults.Serializable has a big flaw. For example, you have a struct X: Codable, Defaults.Serializable. You save data with it, but later on, you add a RawRepresentable conformance. The previous persisted version of the struct can no longer be loaded as it's saved using the Codable bridge, but now tries to load using the RawRepresentable bridge.

// @hank121314 Thoughts? Any better way to prevent this problem?

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