Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"." in a Rust module identifier

A question about gRPC codegen with tonic (uses protoc) under the hood.

The third party protos I am using are have package names like thirdparty.specificpackage, for example:

syntax = "proto3";

package thirdparty.common;

import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

service CommonService {
...
}

and a build.rs that looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

tonic_build::configure()
        .protoc_arg("--experimental_allow_proto3_optional") // for older systems
        .build_client(true)
        .build_server(true)
        .out_dir("./src")
        .compile(
            &[
                "src/myprotoproject/protos/services/decision_engine.proto"],
            &["src"],
        )?;

the generated code from my cargo build is named thirdparty.common.rs – how do I import this into my Rust code?

mod thirdparty.common is not a valid Rust identifier because of the . – are there best practices around this?

>Solution :

If you cannot reasonably control or change the name of the file, you can use a path attribute:

#[path = "thirdparty.common.rs"]
mod thirdparty_common;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading