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

Implement 'Eq' trait for proto #30

Open
ameets opened this issue Sep 11, 2017 · 4 comments
Open

Implement 'Eq' trait for proto #30

ameets opened this issue Sep 11, 2017 · 4 comments

Comments

@ameets
Copy link

ameets commented Sep 11, 2017

Is there a way to specify custom trait implementations, such as Eq, in the proto file for prost-build to generate?

If not, what is the correct way to implement a trait for the generated Rust code?

Thanks!

@danburkert
Copy link
Collaborator

The list of traits currently implemented automatically are Message, Default, Clone, Debug, and PartialEq. Eq is a bit tricky because it can't be provided for messages which include, or transitively include, floating point fields. It should be possible to automatically add Eq to any message type which meets that criteria; prost-build already does a similar recursive graph search to automatically box fields when necessary.

As a workaround in the meantime, you can manually implement Eq for the types you need it on:

pub mod messages {
    include!(concat!(env!("OUT_DIR"), "/messages.rs"));
}

impl Eq for messages::MyMessageType {}

As far as other traits, such as SerDe's Encodable/Decodable, prost-build::Config could be extended with options to add arbitrary derive entries on select message types. That should be very straightforward.

@danburkert
Copy link
Collaborator

PartialOrd/Ord would also be worth adding optional support for.

@megmacattack
Copy link

It would be really nice if it were possible to add serde annotations at generation time. For various reasons it's not sustainable for my team to manually add them to generated protobuf files, but we very much need to be able to convert protobuf to json (we don't much care about round tripping it though).

@danburkert
Copy link
Collaborator

@megmacattack any interest in contributing this? Should be pretty straightforward, it should probably be configurable per path (like the btree_map option is), and then I think it just needs to be inserted into the struct's derives.

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

No branches or pull requests

3 participants