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

feat(codec): allow KeepRaw to own its data #601

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

SupernaviX
Copy link
Contributor

Make KeepRaw store the original data as a Cow<'b, [u8]> instead of a &'b [u8], and add a to_owned method. Justification for this change is in #599, but tl;dr it lets you avoid awkward lifetime problems.

This is a breaking change, the raw_cbor() method now returns a &[u8] instead of a &'b [u8]. In practice, this means that a reference to the raw bytes can no longer outlive a reference to the structure itself.

Also adds an as_ref method to the Nullable<T> helper, to fix a lifetime problem this changed introduced.

@scarmuega
Copy link
Member

@SupernaviX raw_cbor is usually used as ephemeral data for computing hashes, I don't see a concern with constraining the lifetime of the slice.

PR looks good.

@scarmuega scarmuega merged commit 5f9cd2e into txpipe:main Feb 20, 2025
@SupernaviX SupernaviX deleted the keep-raw-cow branch February 21, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants