Skip to content

Decoding composite data items without Default #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chrysn opened this issue Mar 7, 2023 · 0 comments
Open

Decoding composite data items without Default #20

chrysn opened this issue Mar 7, 2023 · 0 comments

Comments

@chrysn
Copy link

chrysn commented Mar 7, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant