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

Name clashes: Include generated code inside of a module which contains the corresponding schema #107

Closed
mashedcode opened this issue Aug 30, 2018 · 2 comments

Comments

@mashedcode
Copy link

mashedcode commented Aug 30, 2018

Currently the user is expected to include all generated code at project root.

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

He then may use that code inside of a module:

// foo/mod.rs
use ::schema_capnp::foo;

This may be inconvenient in some cases and not possible to do with the following structure:

lib.rs
> foo
>> mod.rs
>> schema.capnp
> bar
>> mod.rs
>> schema.capnp

Including both schema files in lib.rs is not possible due to name the obvious name clash.
Therefore one would like to include it directly in the corresponding mod.rs to avoid the name clash.
But currently the generated code assumes that its code will be a module at root level and refers to itself with ::schema_capnp in the example above.
This could be easily modified so that it assumes it's included in the same directory as the schema file is so the resulting handle would be ::foo::schema_capnp.
But that would make it impossible to include it in a different file other than foo/mod.rs (in the example above), which would break the existing behavior.

I don't have a good idea to solve this.

Personally I feel like forcing the user to include the module in the same directory as the schema file would be better than the current behavior. As it's more natural and name clashes would be impossible.

@mashedcode mashedcode changed the title Include generated code inside of a module which contains the corresponding schema Resolve name clashes: Include generated code inside of a module which contains the corresponding schema Aug 30, 2018
@mashedcode mashedcode changed the title Resolve name clashes: Include generated code inside of a module which contains the corresponding schema Name clashes: Include generated code inside of a module which contains the corresponding schema Aug 30, 2018
@dwrensha
Copy link
Member

Thanks for the report. There has been some previous discussion this topic:
#16
capnproto/capnpc-rust#5
capnproto/capnpc-rust#30

@mashedcode
Copy link
Author

Closing in favor of #16. I hope we'll get some progress done there.

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

No branches or pull requests

2 participants