Skip to content

Package-based module structure #2717

Description

@liferooter

Feature Request

Crates

  • grpc-protobuf-build
  • protoc-gen-rust-grpc

Motivation

In the past prost-build and tonic-build were structuring generated code in the same shape as packages in .proto files were structured. That was good. The same scoping in .proto files and Rust code ensured that there's no name conflicts in Rust code as long as there's no name conflicts in .proto files and that module structure is convenient in Rust code as long as it's convenient in .proto files. Sometimes it was slightly too verbose for a reason, but it's easy to create a convenient alias for a module with too long name.

Now grpc-protobuf-build structure generated code in a file-based tree and merge everything together with a lot of use module_name::*. This is not good. It creates name conflicts and completely melts away the package-based namespacing defined in .proto files. This can be overcome by manually compiling each file into its own module, then manually configuring dependencies between them, then manually generating a root module that structures generated modules into expected shape, which is extremely hard and inconvenient.

Proposal

I suggest to add a feature (and probably make it default) for generating Rust code in modules structured the same way as packages in .proto files are structured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions