Skip to content

Add optional postcard feature to enable postcard impl for Value#118

Merged
diondokter merged 1 commit intotweedegolf:masterfrom
adamgreig:postcard
Jan 19, 2026
Merged

Add optional postcard feature to enable postcard impl for Value#118
diondokter merged 1 commit intotweedegolf:masterfrom
adamgreig:postcard

Conversation

@adamgreig
Copy link
Contributor

Allows using postcard with any serde-compatible types.

Originally I had a blanket impl for any T: Serialize+Deserialize, but that conflicts with pretty much every other impl, so the marker trait approach seemed a bit more fine-grained while still being very easy to use.

@adamgreig
Copy link
Contributor Author

Force pushed to fix formatting CI.

@Sympatron
Copy link

Are you sure this is the correct repo? This seems totally unrelated to sequential-storage.

@diondokter
Copy link
Member

diondokter commented Jan 19, 2026

Are you sure this is the correct repo? This seems totally unrelated to sequential-storage.

Yeah, I suggested he add this to the repo :)
You can't do this outside of the repo and there are more convenience impls too.

I am now thinking this could actually be quite sucky in some situations...
Say you have your own type that impls Value and the serde traits.
When you then add a new dependency that uses sequential-storage with the postcard feature, your old code won't build anymore since you have a clash in Value impls.

Not sure how that will play out...
Thoughts?

The code itself looks good though.

@Sympatron
Copy link

Sorry, I didn't realize that Value was a trait of sequentual-storage.

Say you have your own type that impls Value and the serde traits.
When you then add a new dependency that uses sequential-storage with the postcard feature, your old code won't build anymore since you have a clash in Value impls.

Without the blanket impl on T: Serialize+Deserialize this shouldn't be a problem, because you have to manually impl PostcardValue for T {} for T to impl Value automatically with this PR. So as long as you don't implement Value and PostcardValue at the same time you are fine.

@adamgreig
Copy link
Contributor Author

Sorry, I should probably have written a clearer description of the PR! This basically makes it much easier to use arbitrary Rust types as your Value in sequential-storage by allowing you to serialise them to bytes using postcard, which works with anything that impls the serde Serialize+Deserialize traits.

In principle you could even use postcard for all types, remove the trait entirely, and require just that values impl the serde traits, but as that's not backwards compatible this approach is probably better. As @Sympatron says, the marker trait means postcard is only used for types that explicitly opt in to it, so it won't affect any existing code (regardless of whether the feature is enabled).

@diondokter
Copy link
Member

Oh! I didn't read the code correctly.

I saw the marker trait and assumed it would have a blanket impl. My bad :)

@diondokter diondokter merged commit 3e23641 into tweedegolf:master Jan 19, 2026
5 checks passed
@diondokter
Copy link
Member

Released as 7.1.0 :)

@adamgreig adamgreig deleted the postcard branch January 19, 2026 15:16
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.

3 participants