-
Notifications
You must be signed in to change notification settings - Fork 222
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
Is it easy to remove "crate::~" from generated code? #194
Comments
You can put the generated code wherever you want by using the |
Thanks for the pointer, @dwrensha, there was no mention of that in the README, I suggest adding it :). I ended up using the feature as follows (rust.capnp is next to my schemas):
Nonetheless the downside is that your schema is now tied to the internal structure of you project, which won't necessarily remain so forever. In fact, if one wants to reuse the same schema across different code bases one has to change annotation every time. |
Aside from the implementation difficulty of using relative paths, here's another reason I prefer absolute paths in the generated code. Suppose that you have two schemas mod a {
mod b {
mod foo_capnp { /* ... generated code */ }
}
mod bar_capnp { /* ... generated code */ }
} Suppose moreover that I don't see a way to make that work if the generated code relies on relative paths. How would the To take this a step further, imagine that you could I believe that is the ideal world we should be striving for. To get it to work, we'll need to add annotation crate (file) :Text; and we'll need Cargo to support something like rust-lang/cargo#3544. |
Is the parentModule documented somewhere? |
Currently, the only documentation is inline: capnproto-rust/capnpc/rust.capnp Line 17 in d58b59d
I agree that it would be good to add some documentation elsewhere. |
I just stumbled across this problem and I'd kinda expect the |
Yes, I think that would be possible. The new option could be named However, I'm a little bit worried that such an option might interact poorly with schemas that have cross-crate dependencies. If a schema from crate A wants to import some types from a schema defined in crate B, how will it know the Rust path at which to expect the imported types? (Admittedly, my worry here is rather abstract, because rust-lang/cargo#3544 is blocking cross-crate capnp schema dependencies from actually working.) |
Thank you everyone for the input. I have added a |
I think it is better to remove "crate::~" from generated Rust code because I cannot move the generated codec file to wherever I want to put the file in my project.
My suggestion is to use "super::" instead, or use "use" statement for sibling module in each top mod and remove "crate::schema_capnp::".
I tried to customize this plugin like above, but I cannot figure out how to customize "schema_capnp.rs" file in an instant, which I'm guessing is the important part for this issue.
The text was updated successfully, but these errors were encountered: