Skip to content

Decoding composite data items without Default #20

Description

@chrysn

With the currently available documentation it is unclear how a composite type (say, point = [x: int, y: int] / struct Point(x, y) would be decoded. The closest trait to implement is CBORDecodable, but that requires a &mut Point as input, which needs to contain a valid representation before parsing. This may work well for complex types where all components are optional (so that before decoding a default empty instance is created), but needs workarounds like allowing some actually-uninitialized state, and extra safeguards to ensure that that doesn't go wrong.

My impression of CBORDecodable is that it conflates two concerns:

  • It ensures that the struct doesn't get passed around, but is pre-allocated in its eventual position. (I don't know how well the Rust compiler handles return placement in general, but it seems to do well in simple cases.)

  • It simplifies handling of types with many default properties.

I could come up with various suggestions, but think that best progress would be made here if the rationale behind the current API (and possibly examples) were documented. How should a type like the above Point be used with CBORDecodable?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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