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

How to build a list inside an union? #32

Closed
novacrazy opened this issue Feb 11, 2017 · 3 comments
Closed

How to build a list inside an union? #32

novacrazy opened this issue Feb 11, 2017 · 3 comments

Comments

@novacrazy
Copy link

novacrazy commented Feb 11, 2017

I have in my capnp files an union that is akin to Rust's Option type:

struct Option(SomeType) {
    union {
        none @0: Void;
        some @1: SomeType;
    }
}

And I use it to store a List like:

struct Vertices {
    positions @0: List(Math.Point3);
    normals @1: Util.Option(List(Math.Vector3));
    uvs @2: Util.Option(List(TexCoord));
}

And the generated documentation looks like:

option doc

However, it seems that the initn_some method doesn't do anything, as when I try to read back in the data it shows up as None.

You can see Here how I am initializing the builder and attempting to copy the data into it.

And it executes just fine, and all data but the Option(List(_)) types appear to save perfectly.

So is it a bug that Lists inside union types cannot be properly initialized or am I doing it wrong?

Also, set_vector is defined in this file. It's nothing much.

An alternative could be a way to create a list builder without a parent somehow? Then I could just use set_some, but I don't see an obvious way of doing that.

@novacrazy
Copy link
Author

I suppose I could have opened this in the runtime library repo, but since this more has to do with the generated Builder code, eh.

@novacrazy novacrazy changed the title How to build a list inside an enum? How to build a list inside an union? Feb 11, 2017
@dwrensha
Copy link
Member

Thanks for the report! This should be fixed in c248530.

An alternative could be a way to create a list builder without a parent somehow? Then I could just use set_some, but I don't see an obvious way of doing that.

Yeah, this would require orphans: capnproto/capnproto-rust#51

@novacrazy
Copy link
Author

Thanks for the quick fix! Everything seems to be working now.

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