Skip to content

Conversation

@Guiguiprim
Copy link
Contributor

I'm not sure if you will be interested by this PR but I will try my luck as I feel like other might use it (otherwise I will keep it on a fork).

Context: For performance and memory usage reasons I wanted to optimise the data structures I use with prost. In my use-case I wanted to use a string interner for some fields and arrays instead of bytes for others, but this could also be used for small string optimisation or tiny vec and more.

To do it in a generic way, I added:

  • a trait CustomScalarInterface
  • support for a custom_scalar(interface_path) tag in prost-build and prost-derive

This make it possible to implement as a crate user any scalar wrapping type without needing to touch prost. It is an expert API as the user would need to correctly implement CustomScalarInterface in a way that is compatible with the declared protobuf type.

@Guiguiprim Guiguiprim force-pushed the gv/custom-scalar branch 4 times, most recently from 6d2fa16 to f87d51e Compare December 12, 2025 13:36
@Guiguiprim
Copy link
Contributor Author

I just realized this is the same idea as #1230.

I went for a trait instead of a module (as I almost done at first) as I thought it would make the feature easier to use and understand.

I also added support in prost-build which the other did not I believe.

Otherwise naming can obviously be redone if a better one is proposed.

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