Closed BaxHugh closed 2 months ago
Isn't this already provided by the prost::Name
trait, which can be enabled with prost_build::Config::enable_type_names
?
Thanks @romac I'm not sure how I missed this, nothing jumped out of the docs to me, and I failed to find it when grepping around the source code. But yes, this is exactly what I was looking for, so I'll close this.
prost_build::Config::enable_type_names
could use some extra documentation to make it more discoverable.
@BaxHugh Are you willing to add an example to the documentation?
Description:
I would like to request a new feature for
prost-build
to automatically implement aProtobufSrcInfo
trait for each generated struct. Currently, the only info I would like in the trait at the moment would be a constantPROTOBUF_FULL_NAME
to return the full protobuf name of the struct (i.e. the protobuf package + message name), similar to theDESCRIPTOR.full_name
attribute in Python'sprotoc
generated code. I'm sure there would be additional information people might want later.Rationale:
In many cases, it would be useful to have access to the full protobuf name of a message in Rust code, for purposes such as debugging, logging, or interfacing with systems that use the same protobuf API and potentially require the full protobuf names. Currently,
prost-build
does not generate this information, and users need to manually add it somewhere in their code.My Specific Use Case
My specific use case for this feature is cross-language interoperability. Specifically for implementing pyo3 conversion traits on prost generated types. If I can extract the original protobuf path on the rust side at the struct level, I can derive implementations of pyo3 conversion traits as the protobuf path can be used to find the full python path for the equivalent python class that needs to be returned from pyo3 trait implementations.
Some details of my proposed solution
Add a trait in prost.
Add a method to
tonic_build::prost::Builder
or if we need to support the option to only implement this on some messages, we could have a path argument, as we do with
Builder::message_attribute