Skip to content
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

Add support for types that can be records or tuples #153

Merged
merged 10 commits into from
Sep 1, 2023
Merged

Conversation

KodrAus
Copy link
Collaborator

@KodrAus KodrAus commented Aug 26, 2023

This PR adds support for "record tuples"; types that may be treated as either a record or a tuple by a Stream depending on its preference. The default preference is to treat these as records.

The motivation for this is to support types that can be streamed as tuples in binary formats like protobuf, or as records in human-readable formats like JSON, such as:

#[derive(sval::Value)]
pub struct Message<'a> {
    #[sval(index = 1)]
    pub id: i32,
    #[sval(index = 2, tag = sval_protobuf::tags::PACKED)]
    pub data: &'a [i32],
}

Alternatively, this same type could be defined as a tuple:

pub struct Message<'a>(
    #[sval(index = 1, label = "id")]
    i32,
    #[sval(label = "data", tag = sval_protobuf::tags::PACKED)]
    &'a [i32]
);

If a record has any fields with index specified then all fields must have it. Likewise for tuples and label.

@KodrAus
Copy link
Collaborator Author

KodrAus commented Sep 1, 2023

I've been working on a protobuf implementation based on this just to sanity check everything. I think it all works out nicely, so I'll merge this one, but will wait until the protobuf support is complete before releasing.

@KodrAus KodrAus merged commit 2ca2dee into main Sep 1, 2023
38 checks passed
@KodrAus KodrAus deleted the feat/record-tuple branch September 17, 2023 22:23
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

Successfully merging this pull request may close these issues.

1 participant