capnproto-rust icon indicating copy to clipboard operation
capnproto-rust copied to clipboard

Annotation and struct module names can conflict

Open dzfranklin opened this issue 2 years ago • 1 comments

In the capnp docs they mention a pattern where an annotation and the struct for its value share the same name.

struct Grault {
  value @0 :Int32 = 123;
}

annotation grault(file) :Grault;

Because both annations and structs get corresponding rust modules the generated code won't build.

I'm not sure what the right solution is here. A robust but maybe annoying option would be to add a prefix to annotation modules so you get something like annotation_grault and grault. Just naming the struct GraultOpts isn't a big deal either.

dzfranklin avatar Jun 04 '23 23:06 dzfranklin

One thing we could do is make the $Rust.name annotation work on annotations: https://github.com/capnproto/capnproto-rust/blob/977b3db3f97c142a0d6dff50302aa42908858fc9/capnpc/rust.capnp#L9

dwrensha avatar Jun 06 '23 01:06 dwrensha